If they click at the exact same millisecond, who wins?

The winner is determined by serialization. Redis is single-threaded. It processes commands one by one from a queue.

Even if two requests leave the users' devices at the exact same time, physical constraints (network routing, switch buffers, OS kernel interrupts) ensure they arrive at the Redis "door" in a single file line. Redis never executes two commands in parallel.

network_check 1. Network Arrival

Packets travel over wires. Physics dictates they cannot occupy the exact same space on the wire/port. The OS network stack puts them in a receive buffer.

queue_music 2. The Queue (Critical)

Redis reads from the OS buffer. The first readable command goes into the execution slot. The second must wait, even if it's just for 0.0001ms.

lock 3. Atomic Execution

Because they are processed sequentially, the first one executes SET NX and succeeds. By the time the second one runs, the key exists.

The "Microsecond Showdown" Lab

Visualize the single-threaded event loop in slow motion.

speed SIMULATION SPEED:
Client Layer
Network / Kernel Buffer
Redis Single Thread
A
Alice
IP: 192.168.1.10
IDLE
B
Bob
IP: 192.168.1.15
IDLE
COMMAND QUEUE (FIFO)
PORT:6379
Redis
MAIN THREAD
IDLE
Memory Store
(Empty)
redis-server --port 6379
# Server initialized
# Waiting for connections...