AlgoViz

Concurrency in an LLD round

medium 40 min

Sooner or later the interviewer asks what happens when two users do it at the same time.

Watch lesson5:07

When it comes up

The moments this idea belongs in a design interview, and the moments it does not.

Words in the prompt

You hearThinkFirst sentence
"Several gates", "many users"CorrectnessWhich rule breaks if two act at once?
"In the background", "when it is done"CoordinationWho waits, and who wakes them?
"Only five", "at most", "pool"ScarcityWhat happens to the sixth?
"Process them in order"CoordinationOrder over all, or per customer?
"Is it thread-safe?"All threeLet me go field by field
"Very fast"Price of the guardWhat is inside the lock, and is it needed?

Nobody has mentioned threads, and your design has a shared class. What do you do?

BreaksSay nothing
How
Hope that it does not come up.
Limit
It looks as if you did not see it, and the first follow-up finds you unprepared.
Choose when
Never.
WorksAdd locks at once
How
Write the class with locks from the start.
Limit
Costs time, and the logic is harder to read while it is still changing.
Choose when
When the prompt is about concurrency itself.
StrongAsk, mark, return
How
Ask in scope. Mark the critical lines with a comment. Return in verification with four sentences.
Limit
You must keep five minutes for it.
Choose when
The default.