~learn.
0:00 / 1:32
Mock interview · Paisly

You typed the right OTP. It said invalid.

transcript

You type the right OTP. The app says: invalid. The interviewer asks: why do 1 in 200 correct codes fail?

One change shipped. An engineer moved reads to the Redis replicas. To spread the load. Since then, correct codes fail at the evening peak.

Sending the code writes it to the primary. Copying to the replica is async. At peak, seconds behind. Auto-read submits the code within seconds of the SMS. Verify reads the replica. The code isn't there yet. Right code. Invalid OTP.

The interviewer: so it's a small annoyance? One in 200? The candidate: it's worse. Two more bugs hide here.

One: false rejections. Users already see those. Two: the attempts counter is stale. An attacker gets more than five guesses. Three: a used code still looks valid on the replica. A replay window.

The fix: verify reads the code, checks it, and changes it. So it runs as one atomic script, on the primary. Here, replicas are for failover. Not for reads.

And if the primary dies before copying a fresh code? That code is lost. The user taps Resend. Acceptable.

Replica reads look like free capacity. For a code you just wrote, they aren't. Read your writes, for the keys that need it.

Full breakdown in the lecture.