Loading...
Loading...
Browse 17 real-world technical and behavioral interview questions about Concurrency. Review scenarios, edge cases, and architectural best practices.
A timeout requests cancellation; it does not stop code. CancelledError is raised at the task next await point, so a task inside blocking code, shielded, in an executor thread, or swallowing the exception keeps running and commits its side effects late. Fix by re-raising CancelledError, keeping blocking calls off the loop, and using asyncio.timeout with a TaskGroup.
A rate limiter machine coding solution should reject fixed-window boundary bursts, usually with a token bucket. It needs no per-request history and stores two numbers per client, but only if refill is computed lazily from a timestamp rather than by running a background thread. Use this rate limiting answer to show the decision, trade-off, and evidence rather than a memorised definition.
Thread-safe component design starts by assigning every field a policy: confined, immutable or guarded by a named lock. Method-level synchronization is not enough because atomic methods do not compose into atomic workflows.
Designing an ultra-low latency distributed lock manager, evaluating consensus algorithms, and handling clock drift in high-frequency environments.
Every reservation must decrement the shared pool and the member's own counter atomically, granting the smallest of the two remainders. That makes the group rather than the subscriber the serialisation point, and it means a member with headroom can still be refused because the pool is gone.
They are false sharing: both counters sit in one cache line, so each write invalidates the other core's copy and the line ping-pongs between caches. You fix it by aligning each hot field to its own line, at the cost of footprint, and only where a hardware counter says so. It also connects cache lines to the point an interviewer is testing.
Ride matching system design should rank drivers by estimated pickup time and market impact, not straight-line distance. Offer the ride under a short soft lock, use a small batching window when it improves assignment quality, and keep the rider wait within a few seconds. Use this dispatch answer to show the decision, trade-off, and evidence rather than a memorised definition.
The Python GIL serializes CPython bytecode execution, but threads still help I/O-bound work; choose processes for pure Python CPU work and asyncio for many concurrent waits.
Thread safety composes per operation, not across operations. A get followed by a put is two atomic steps with a legal interleaving between them. You close the window by making the whole compound action one operation, such as compute or merge, or by holding a single lock across both steps.
A producer-consumer bounded buffer applies backpressure to the producer instead of letting an unbounded queue absorb overload until the process dies. Deciding what a full buffer does - block, drop, or reject - is the decision that determines how the system fails.
Treat availability as a claim you grant, not a number you read: fold the check and the decrement into one conditional write, hold the winner's claim as a reservation that expires, and choose deliberately how much overselling you accept, because the warehouse and not the database is the real source of truth.
A deadlock is a cycle in the wait-for graph, so the design goal is a graph that cannot contain one: stop holding two locks where you can, impose one total order on acquisition everywhere you cannot, and never call unknown code while holding a lock.
EF Core optimistic concurrency uses a rowversion or concurrency token so a stale update affects zero rows instead of overwriting another user's change. The application must then merge, retry or ask the user.
Interrupt service routine rules are simple: acknowledge the hardware, capture the minimum safe state and return fast. Blocking calls, allocation, logging and long loops belong in deferred work because ISR runtime becomes worst-case latency for interrupts at the same or lower priority.
A context switch in an operating system saves one thread's CPU state, runs the scheduler and restores another thread. Application developers care because excessive switches add latency through cache and TLB disruption, lock contention and oversized thread pools. It also connects scheduling to the point an interviewer is testing.
Virtual threads make blocking cheap by unmounting from their carrier OS thread whenever they block, so thread-per-request scales to hundreds of thousands of concurrent tasks. Finalised in JDK 21, they do nothing for CPU-bound work, and pooling them defeats their purpose.
In Go, the sender closes a channel when no more values will be sent; receivers do not close it just because they are done. Multiple senders need coordination so close happens exactly once after all sends finish. Use this channels answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects goroutines to the point an interviewer is testing.