parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

feat: Graceful Redis cache adapter fallback

Open pocketcolin opened this issue 10 months ago • 3 comments
trafficstars

New Feature / Enhancement Checklist

Current Limitation

If you are using the Redis for the Cache Adapter and your Redis instance goes down, it will crash the Parse server.

Feature / Enhancement Description

A graceful fallback for temporary Redis outages. One possible solution could be to have a configurable Redis request timeout (maybe defaults to 5 seconds) where if Redis doesn't respond fast enough, a new request is made to the database for the same information. Note that one of the biggest complicates for having a Redis cache fallback is dealing with the potentially stale Redis data when it comes back online. I don't know how we'd want to deal with that and it might be a deal breaker, but posting this anyway because @mtrezza asked me to!

Example Use Case

  1. Running Parse Server with a Redis Cache
  2. Redis host goes down
  3. Your Parse Server continues running (albeit in a degraded state) until either your host brings your Redis cache back online or you turn off Redis temporarily until issues can be resolved.

Alternatives / Workarounds

You can disable the Cache Adapter manually when you expect Redis downtime.

3rd Party References

https://www.michaco.net/blog/WhatIfRedisStopsWorkingHowDoIkeepMyAppRunning

pocketcolin avatar Jan 10 '25 18:01 pocketcolin

Thanks for opening this issue!

  • 🎉 We are excited about your ideas for improvement!

Sounds interesting, the Redis data may be outdated in any case, whether there's a fallback or not, so I believe that's a separate challenge. The fallback itself can keep an app at least operational, at the cost of querying directly from the DB, rather than bringing the server down due to a temporary connection issue to the Redis server. A possible solution may be to flush the Redis server once it comes back online, so that it's essentially self-healing by rebuilding the cache.

mtrezza avatar Jan 10 '25 18:01 mtrezza

You can try to use redis retry strategy. I added it to the Redis Pubsub for LIveQuery and it works great! Might need to do a PR to pass options to the RedisCacheAdapter

https://github.com/parse-community/parse-server/issues/5387

dplewis avatar Mar 11 '25 23:03 dplewis