Search code examples
google-cloud-platformredisgoogle-cloud-memorystore

How to ensure consistency between multiple GCP cloud memory store instances?


I have my application caching some data on cloud memory store. The application has multiple instances running on the same region. AppInstanceA caches to MemStoreA and AppInstanceB caches to MemStoreB. A particular user action from the app should perform cache evictions. Is there an option in GCP to evict the entries on both MemStoreA and MemStoreB regardless from which app instance the action is triggered?

Thanks


Solution

  • You can use PubSub for this.

    • Create a topic
    • Publish in the topic when you have a key to invalidate
    • Create 1 subscription per memory store instance
    • Plug 1 function (each time the same function) per subscription with an environment variable that specifies the instance to use

    Like this, the function are trigger in parallel and you can expect to invalidate roughly in the same time the key in all memory store instances.