Practice · 2 of 2
Read-after-write under eventual consistency
CHALLENGE
Difficulty: advanced+25 XP
Implement class EventualStore(int replicationDelayMs) with void Write(string key, int value) (primary immediately; replica after the delay via Task.Run) and int? ReadStale(string key) (reads the replica, may miss recent writes) plus int? ReadPrimary(string key) (always current). Implement static async Task<bool> ReadAfterWriteHolds(EventualStore store, string key) that writes 42, reads the replica IMMEDIATELY — and returns whether the read saw the write (it must NOT, with a real delay; the test then waits past the delay and requires the replica to converge).
Press Submit to check your solution.
Back to lesson: Practice: Distributed drills