How to handle synchronisation of request at KongAPI Gateway?

I have been trying to implement request/response caching at reverse proxy level(Kong API Gateway). So whenever the request will come to API gateway, it will check into cache store weather the given request response present in cache store or not(redis cache store). if it does not exist then request will be forwarded to origin server and then response will be saved to cache store and return it back to client. Any successive call for same resource will hit API gateway and response will keep on serving from cache store until it is invalidated.

My case is:-

let say their is post call POST /api/details/customer/{id} and simultaneously their are no of GET /api/details/customer/{id},

Consider a Scenario(Race Condition)

Now let say whenever the POST request come for any resources on API Gateway, I can mark invalidate the response in the cache store before forwarding the request to Origin Server,

Meanwhile any successive GET call for same resources will see the cache miss in cache store and also forwarded to origin server.

So it can be possible GET call completed before the POST call and cache store will save the stale data.

How to handle such cases? is there any way to handle synchronisation at LUA plugin ? or is there any way to do so?

You could invalidate the cache and re-populate it after the POST call succeeds.
In that case, any GET request before the POST call will receive the old data (as intended) and all request after the POST call will receive the updated data.


© 2018 Kong Inc.    Terms  •  Privacy  •  FAQ