I would like either both of them to succeed or both of them to fail. How is this problem generally handled?
What do you mean?
I'd imagine the source of truth is MongoDB, and I'd imagine Redis is on top of MongoDB.
So, if the key has an expiration date, when it's expired you can ask MongoDB to give you the updated data.
During write you can write in MongoDB and invalidate the cached key so that the next read from Redis will fill the value from MongoDB.
Let me know if it makes sense or not :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What do you mean?
I'd imagine the source of truth is MongoDB, and I'd imagine Redis is on top of MongoDB.
So, if the key has an expiration date, when it's expired you can ask MongoDB to give you the updated data.
During write you can write in MongoDB and invalidate the cached key so that the next read from Redis will fill the value from MongoDB.
Let me know if it makes sense or not :)