Redis › Caching Patterns
What is the write behind, also called write back, caching pattern, and what risk does it introduce?
IntermediateAnswer
In the write behind pattern, data is written to Redis immediately and then asynchronously written to the database a short time later, which improves write speed since the application does not wait for the slower database, but introduces the risk of losing recently written data if Redis crashes before that data reaches the database.
redis.set(f'order:{order_id}', order_data)
-- A background worker later reads from Redis
-- and writes the same data to the databaseReal-world example A high throughput analytics system writes events to Redis instantly for fast response times, using a background worker to batch and persist those events to the database a few seconds later.