samedi 19 janvier 2019

How to process pagination with cached response?

I’m developing two microservices, which deal with subscriptions and users, where one is a data server and second is RESTful web one.

They interact with each other through Kafka.

To reduce a number of calls to data server I introduced a Redis cache in my web server.

Now, when a user retrieved his subscription, the web server first asks Redis for them, if they are absent, it retrieves them from data server and put to Redis.

Also, if user subscribe to another user, then the subscription is put into Redis after persisting into database.

I’m going to introduce pagination and a serious problem has raised.

A case when user retrieves his subscriptions from x to n and they are put into a cache and after retrieved in a repeated request is pretty straightforward.

What should I do when user subscribes and a new subscription is put in the cache?

User retrieves N records, then cache contains N records. User subscribes, a new subscription is put into cache. Now Redis contains N+1 records.

How to deal with pagination if user then asks from N to 2N records?

I bet it’s a well-known problem and a common solution exists.

Aucun commentaire:

Enregistrer un commentaire