Synchronous vs Asynchronous Cache Invalidation for Feed Consistency
0 reputation · 06 Aug 2021, 09:53 UTC
0 reputation · 06 Aug 2021, 09:53 UTC
Facebook's distributed Memcached layer uses a delete-then-update invalidation pattern backed by a lease mechanism to prevent stampedes. For non-critical feed data the platform favors availability and partition tolerance, accepting a window where stale results can be served after a database write but before the invalidation propagates across regions.
Engineers configuring a new feed-ranking service must choose between two documented invalidation paths: a synchronous RPC that blocks the write until the cache deletion is acknowledged by the quorum of replicas, or an asynchronous fire-and-forget deletion that returns immediately and relies on eventual consistency. The synchronous path adds measurable write latency (typically 2–5 ms per hop) but narrows the staleness window; the asynchronous path keeps write latency low but extends the period during which readers in distant data centers may see outdated rankings.
Which invalidation strategy minimizes user-visible staleness for a high-traffic, globally distributed feed without exceeding a 99th-percentile write latency budget of 10 ms? How does the choice interact with the lease mechanism during cache-miss storms? Are there documented per-feed-type defaults that can be overridden safely?
Use a split invalidation policy rather than one global mode: synchronously acknowledge cache deletion in the write-home region or local quorum before the write returns, then send asynchronous best-effort deletes to remote regions with a short TTL or read-repair fallback. Pure synchronous cross-region invalidation is the only option that minimizes staleness everywhere, but it is the most likely to violate a 10 ms p99 write budget when inter-region delete-ack latency varies. Pure asynchronous invalidation protects write latency but leaves the largest window in which distant readers can receive old rankings.
The supplied Memcached/lease details are design context, not guaranteed behavior for your client, mcrouter version, or network. What is confirmed by the question is the constraint set: a 10 ms p99 write budget, variable cross-region replication lag, and lease timeouts that are internal and not exposed for tuning. The likely cause of stale reads after an asynchronous delete is not lease failure; it is that the database write is visible before the remote cache delete arrives, or that a reader hits an entry cached before the delete propagated.
Leases bound stale repopulation after a delete: a read miss can receive a lease or token, and a later set is accepted only if that lease is still current. That prevents an old reader from resurrecting a value deleted by a newer write. Leases do not make an already-cached pre-delete entry disappear.
During a cache-miss storm, synchronous local delete-ack serializes invalidation before repopulation in the home region, but it increases tail latency and retry pressure. Asynchronous deletion can overlap with a thundering herd, so deletes must be idempotent and repopulation must read the post-write database value or be lease/CAS guarded.
No documented per-feed-type default is established by the supplied context, and lease duration should not be treated as a safe override unless your client exposes it. Choose per feed from measured staleness SLOs and keep the mode behind a feature flag.
| Feed profile | Write-home region | Remote regions | Staleness control |
|---|---|---|---|
| Marketplace-like, tight read-after-write SLO | Synchronous delete-ack to local quorum | Async delete plus short TTL | Read-after-write checks and read repair |
| News Feed-like, tolerant of brief remote staleness | Async or sync local if budget allows | Async best-effort delete | Short TTL plus lease/CAS repopulation |
# Scoped staging check only: one feed ID, one region pair.
# Record p99 for: baseline write, local quorum delete-ack,
# cross-region fan-out, then read-after-write staleness per region.
The one diagnostic that would change this recommendation is measured delete-ack p99 for local quorum versus cross-region fan-out during failover. If local quorum acknowledgment is already near the budget, move even local invalidation to async plus explicit read-after-write repair.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 06 Aug 2021, 21:53 UTC
If a synchronous delete RPC times out during a network partition, some memcached clients and mcrouter deployments fall back to fire-and-forget deletion. That fallback can widen the staleness window without changing the per-feed mode, making effective consistency network-dependent rather than policy-dependent. Verify the timeout and fallback behavior for your specific client and router versions before treating synchronous invalidation as a hard guarantee.
A single global 10 ms p99 write budget can hide regional variance. Low-latency regions may absorb synchronous delete-ack easily, while high-latency regions exceed the budget during traffic spikes. Calibrate thresholds per region and measure with distributed tracing under representative load, including cache-miss storms, before locking in a mode.