parse-server
parse-server copied to clipboard
feat: Graceful Redis cache adapter fallback
New Feature / Enhancement Checklist
- Report security issues confidentially.
- Any contribution is under this license.
- Before posting search existing issues.
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
- Running Parse Server with a Redis Cache
- Redis host goes down
- 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
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.
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