mostread.io

Implementing ‘Most read’ for publishers

Having worked on several projects for pure play digital publishers, one area we have some experience with is implementing a ‘most read’ feature.

footnote

For low traffic sites, it’s easy to add an integer field to your content model and increment it when you pull that content down. However, for high traffic sites this doesn’t work well. It consumes a lot of GraphQL non-CDN API calls, which can get expensive quickly, and even
worse it means every page load invalidates your CDN cache, which can cause major performance issues.

We typically implement this with a separate simple database (Azure table storage, DynamoDB, even Postgres). If you’re looking to get something similar up and running, you need to store each page load as a row, with the datetime and Contentful ID of the page.

You can then use an ajax (to improve catchability of the main page) request on page load to a simple endpoint that can manage this logic When you want to then rank items by most read, call both Contentful and this table storage, and perform a simple query on it to transform and sort by most read.

Working through this problem we realised that nobody has built a simple Contentful plugin that can run the logic for you. We decided this would be a worthwhile internal project to work on and it’s currently in development – so watch this space.