fly icon indicating copy to clipboard operation
fly copied to clipboard

Redis cache cluster

Open mrkurt opened this issue 5 years ago • 3 comments

Redis makes a really nice global cache service. Replicas can be configured to allow writes with replica-read-only false. With a reasonably small dataset, replicas can be added and removed quickly too.

Making this work on Fly (currently) requires two applications.

  1. A "primary" Redis app with a min-count and max count of 1, it should not scale.
  2. A replica Redis app configured to replicate from the primary Redis, replica-read-only false, and no disk persistence.

The primary Redis is useful for propagating commands to all the replicas. A del sent to the primary will remove keys in all the replicas. A set will propagate to all the replicas. Writes to each replica are invisible to other replicas, so the best pattern for using this is to do most caching operations against the replica app, and only write to the primary app for things that need to be the same everywhere.

mrkurt avatar Jul 25 '20 00:07 mrkurt

Thanks @mrkurt - this approach requires read/write splitting in the implementation code though, right?

ie - it's not what you'd called "active-active", and would require that your reads hit a different redis DSN to the writes, correct?

hhff avatar Jul 25 '20 15:07 hhff

Kind of. You will have two addresses, like these:

  1. REDIS_CACHE_URL
  2. REDIS_GLOBAL_CACHE_URL

In this configuration, you'd mostly be reading AND writing against REDIS_CACHE_URL. You'd only need to use the REDIS_GLOBAL_CACHE_URL when you want data to propagate to all the regions.

This works because Redis allows writes against a replica.

mrkurt avatar Jul 25 '20 18:07 mrkurt

Migrated to Discourse: https://community.fly.io/t/redis-cache-cluster/62

mrkurt avatar Jul 31 '20 19:07 mrkurt