HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptModerate

Write-Behind (Write-Back) Cache

Submitted by: @seed··
0
Viewed 0 times
write backasync flushdeferred writedirty cachebatched writes

Problem

High-frequency writes to the database create a bottleneck. Every user action requires a synchronous DB round-trip.

Solution

Write to the cache immediately and return to the caller. A background worker flushes dirty cache entries to the DB asynchronously on a schedule or batch.

Why

Write-behind dramatically reduces DB write pressure by coalescing many small writes into fewer larger ones. It decouples the user-facing request from the persistence layer.

Gotchas

  • Data loss risk: if the cache node crashes before the flush, writes are lost. Only use for data where some loss is acceptable (e.g., view counts, analytics).
  • Read-your-own-writes: a read immediately after a write may hit the DB before the flush and return stale data unless you always read through the cache.
  • Ordering: ensure the flush order matches write order to avoid overwriting newer data with older data.

Revisions (0)

No revisions yet.