Module 05 · Synchronization · Drill
Synchronization drill
Scenario prompts that check whether synchronization is usable under pressure. Answer out loud, then compare.
0 of 4 graded
Prompt 1
A ticketing service checks whether a seat is free and then inserts a booking. It runs on 12 servers with a shared Postgres database, and a few seats per week are sold twice. Explain the race in threading terms, show why adding a mutex in the service does not fix it, and give the correct fix.
Prompt 2
A payments service occasionally hangs: thread dumps show two threads each holding one account lock and waiting for the other. Separately, the database logs 'deadlock detected' a few times a day for the same transfer code. Explain both, and give a design that eliminates the first and handles the second.
Prompt 3
Design a bounded work queue between 4 producer threads (parsing uploaded files) and 16 consumer threads (writing to a database) using only a mutex and condition variables. Explain each wait and signal, and what happens when the database slows down.
Prompt 4
A metrics library increments a shared 64-bit counter per request using a mutex, and at 2 million requests per second across 48 cores the increment shows up as a top hotspot. Propose a faster design, compare it to a single atomic counter, and state the memory-ordering requirements.