How it works
Read replicas
Each shard can keep a memory-only copy in other regions, fed from its AOF. Routers read the nearest one, a connection always reads its own writes, and an idle database's replicas sleep.
Regions
With a replicas list, every data shard keeps one replica in each listed region. Writes always go to the primary. Like the shard count, the list is fixed when the database is created.
curl -H "authorization: Bearer $TOKEN" "$BASE/db?db=mydb&shards=4&replicas=world"A router maps where it runs to one of the nine regions and reads from the replica there, including the primary's own region. With none there, it tries a neighbour; with no match, the primary.
| Router in | Then tries |
|---|---|
| wnam, enam | each other |
| weur, eeur | each other |
| apac, oc | each other |
| sam | enam, wnam |
| me | eeur, weur |
| afr | weur, eeur |
Copy, then stream
The primary sends its AOF files as commands, then every append after them, over one socket per replica. The stream leaves through the primary's output gate like its replies, so a replica only receives committed writes. Its +PONG to the marker means it has run everything before it, and only then does it serve reads.
Replicas run with import-mode and no memory limit, so they never expire or evict keys on their own. Reads still hide expired keys, and the primary's stream deletes them.
What a replica read can see
A read goes to a replica only if all of these hold, and to the primary otherwise:
- It is read-only, doesn't block, and its keys are in one slot.
- The connection is not in MULTI and has no active WATCH.
- The connection has no write in flight to that shard, and none answered in the last 2 s.
- No router in the same process saw that replica fail in the last 5 s.
So a connection reads its own writes while replicas are under 2 s behind. A read on another connection can be one replication lag old: p50 3 to 41 ms, p99 38 to 141 ms across nine regions at light load.
WAIT numreplicas timeout returns how many replicas have every write the connection made, counting the shard it wrote to with the fewest. It adds visibility, not durability. WAITAOF answers 1 0, since every reply already waited for its shard's commit.
Failures
- A replica resets. It starts empty and refuses reads. The primary copies it again 5 s later, and reads go to the primary meanwhile.
- A replica falls behind. Unsent replication bytes count toward the primary's 16 MB input budget, so lagging replicas slow writes down. One more than 8 MB behind, or silent for 60 s, is dropped and copied again.
- The primary resets. Its replicas keep serving what they have, which may miss its last writes, until it copies them again, about 10 s later.
- The primary stops streaming to a replica it drops: it tells the replica to reset, so a replica never serves data that has stopped updating.
Idle sleep
After 10 minutes with no writes, no client activity on the primary and no replica reads, the primary retires its replicas, closes the streams and stops its alarm, so every object can be evicted. The next activity wakes it and it copies every replica again. A read meanwhile finds its replica retired and goes to the primary, which wakes it too.