Redis 00:00:01 Two fans tap the heart A stadium scoreboard holds ten likes. Two people press the heart together. Follow the commands through one Redis server and predict whether the scoreboard ends at eleven or twelve. Both clients send INCR likes at the same moment. The value is 10. Redis runs the first command from start to end. likes becomes 11. Only now does the second run. likes becomes 12. No update is lost and no lock was needed. A long command can hold up other requests. Iterating a large keyspace in shorter cursor-based calls gives other clients opportunities to run. An individual Redis increment performs the read and update together. Splitting that same idea into a client-side read followed by a separate write changes the concurrency guarantee. 00:00:55 What the disk remembers The scoreboard operator can rebuild a count from an event log, or ask Redis to preserve it. Now compare three persistence setups under one hypothetical power failure. The first write arrives at ten o’clock. The next comes two minutes later. Two more arrive in the last second before ten oh five, eight tenths of a second before failure and then one tenth before it. The last snapshot was taken at ten oh one. Power fails at ten oh five. With the snapshot alone, the restart recovers its ten-oh-one state. Writes accepted after that snapshot are outside it. In the illustrated every-second append-only setup, one write falls after the last successful disk sync and is absent after restart. With an append-only sync on each write, the illustrated acknowledged writes survive this power failure. The disk is now on the acknowledgement path. The graph is a recovery budget. An acknowledgement from memory means something different from an acknowledgement tied to durable local storage. Include the storage failure assumptions when you choose a mode. 00:02:03 The standby gets the whistle A second Redis server follows the primary asynchronously. Sentinel observes those servers and coordinates failover. A machine can be promoted successfully while still missing a recent write. The application writes to Redis A. B follows with a small delay. Sentinels watch both. The primary stops responding in this example. Its newest write had not yet reached the replica. The configured quorum of observers agrees that the primary is down. An elected Sentinel coordinates promotion of an eligible replica. Clients must discover and use the new primary. Distinguish the observers' agreement that a primary is down from the majority authorization required to elect the Sentinel leader. Neither supplies a write that replication never delivered. 00:02:51 Two keys on one shard At the next arena the scoreboard outgrows one machine. Redis Cluster assigns keys to hash slots. Pick a key and use the slot map to find which primary currently owns it. The first key maps to slot ten thousand seven hundred seventy-eight, owned by shard two in this map. The next key maps elsewhere. An ordinary lookup can route to its own shard. The profile and settings in this example land in different slots. A multi-key operation requiring one slot cannot proceed as written. Give both keys the same hash tag. They now map to slot five thousand nine hundred seventy, so the operation can be routed together. A hash tag deliberately co-locates keys for operations that need one slot. Too many high-traffic keys sharing the same tag can also concentrate the load you meant to spread out. 00:03:41 Spend one network round trip A client now has a hundred independent operations. A small round-trip delay can dominate a fast server when the client waits for each answer before sending the next request. At half a millisecond per network round trip plus one hundredth of a millisecond of processing, one hundred sequential operations cost about fifty-one milliseconds in this example. A pipeline can send independent operations without waiting between them. With the same simplified assumptions, one round trip plus one millisecond of work takes about one and a half milliseconds. Return to the two fans. Redis still executes their increments individually and the counter reaches twelve. Pipelining changes when the commands travel, not the atomicity of a multi-command workflow. The whole exercise turns on three boundaries. An atomic command protects one update, persistence and replication protect different failures, and pipelining changes the cost of communicating with the server.