Consistency guarantees¶
What paceapi guarantees exactly and what is approximate, for each store and feature. Each claim links to the page that covers it in full.
Rate limits¶
| Setup | Guarantee |
|---|---|
MemoryStore |
Exact within one process. Each worker keeps separate counts (N workers allow up to N times the limit), and counts are lost on restart. At most max_entries buckets (default 100,000) are kept; beyond that the least recently written is evicted. |
RedisStore |
Exact across all processes. Each check-and-count is one atomic server-side script using the server's clock, so two concurrent requests can never both take the last unit. On Redis Cluster, the keys of one limit share a slot. |
Custom algorithm on RedisStore |
Exact, but slower: optimistic read-modify-write in your process. A write that keeps losing the race is denied, never admitted uncounted. |
MongoStore |
Exact across all processes on standalone MongoDB, replica sets, or Atlas (using ReadPreference.PRIMARY and an acknowledged write concern; use w="majority" on replica sets for primary-failover durability). Rates for one limit live in one document updated via single-document compare-and-swap using MongoDB's server clock. Contention exhaustion fails closed. |
MemcachedStore |
Exact across all processes. Rates for one limit live in one Memcached item updated via single-key gets/cas. Uses the host clock (requires NTP across workers), and evicted counters reset early under memory pressure. Contention exhaustion fails closed. |
Exact counting is separate from what an algorithm counts. FixedWindow and TokenBucket enforce exactly what they define; SlidingWindow is an approximation by design (see Algorithms).
When the store fails¶
- Timed-out calls may still have counted: The limiter stopped waiting, but the server may have completed the write.
- Uncounted requests follow
on_store_error:"allow"(default) admits them,"deny"rejects them, and"raise"raises for your code to handle. None of the three counts the request. - Circuit breaker: After repeated failures the store is skipped for up to
store_cooldown, and requests in that window follow the same policy without a store call. - Fallback stores count separately: An in-memory fallback counts per process while the primary is down, and its counts are not replayed to the primary on recovery.
- Evicted counters reset: A Redis server under memory pressure may evict a counter early, restarting that caller's count.
See Failure modes and Memory limits.
Outside the store¶
- Limits only count requests that reach them: Requests answered or rejected by outer middleware are never counted.
- Missing keys: A key that returns
Nonefails the request unlesson_missing_key="skip". Skipped requests are not counted. - Separate
limit()dependencies are separate steps: A request admitted by one and rejected by a later one stays counted by the first. Rates passed to a singlelimit()are all-or-nothing (see Combining multiplelimit()dependencies). - Post-execution charges are not exact: Meters and
count="failures"check on entry and charge afterwards, so concurrent in-flight requests are all admitted and a caller can overshoot by what those requests go on to charge (see Meters, failure counting, and WebSockets).
Caching¶
- Invalidated values are never written back: Every entry records the tokens it was written under and is stored only if they are unchanged at write time, so a load that started before an invalidation cannot repopulate the cache (see Preventing stale write-backs).
- Invalidation is one write, as durable as the store: A Redis failover (or a MongoDB primary failover under
w=1) that loses recent writes, or a snapshot restore, can undo one. Token eviction is fail-safe: old entries become misses (see Durability and consistency caveats). MemoryStoreis per process: Writes and invalidations in one worker are invisible to the others.TieredStoretrades freshness for round trips: A process may serve its local copy for up tolocal_ttlseconds after another process changes the value. Changes made through the same store instance are visible immediately (see Tiered store).- Browser caches ignore server invalidation: A response sent with
client_ttl=is reused by the client until it expires (see HTTP headers). - Single-flight is per process: Concurrent misses for one value run the loader once per process while the store is readable. If reads fail or the cache is disabled, every caller runs the loader.
lock=Trueextends this across processes on a best-effort basis, never as a guarantee. Cached responses are not single-flighted; useCoalescingMiddleware(see Stampedes and stale values). - Store errors: Failed reads are misses. Failed writes and invalidations raise, because a silently lost invalidation would leave stale data behind.
Process-local state¶
In-flight counts, event-loop lag, and the set of requests currently being served are per process and never shared between workers. That covers every concurrency limit, deadline, load shedder, and coalescing middleware: 10 slots in each of 4 workers is 40 across the app (see Middleware order).