Skip to content
Preptima

Top 9 Cancellation Interview Questions

Browse 9 real-world technical and behavioral interview questions about Cancellation. Review scenarios, edge cases, and architectural best practices.

Design a chat service that streams model output to users and lets them press stop. What has to happen when they do?

Stream tokens over server-sent events or a WebSocket, but treat stop as a server-side command routed to whichever worker owns the generation. That worker aborts the upstream model call, saves the partial reply with a stopped status, and sends a final event so the client and the stored history agree.

harddesign

A gRPC call three services deep hangs, and so does everything waiting on it. What was missing?

A gRPC deadline. gRPC sets none by default, so a client waits as long as the server takes, and every caller up the chain holds a thread or stream with it. Set a deadline at the edge, propagate the remaining budget on every hop, stop work on cancellation, and retry only inside what is left.

hardscenario

An asyncio call times out and you handle the TimeoutError, but the background task keeps running and mutates shared state a few seconds later. What happened, and how do you make the timeout actually stop the work?

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.

hardconcept

A customer bought cover on your site last night and this morning the card payment failed. Are they on risk, and what does your system do next?

They are almost certainly on risk, because the contract was formed when you accepted the risk and not when the money cleared. The remedy is cancellation for non-payment, which runs forwards from a notice date rather than erasing the policy, so the system needs a pending-cancellation state and an answer for a claim inside the unpaid window.

hardscenario

A client disconnects but your server keeps working on their request. How does cancellation actually propagate in .NET?

A CancellationToken in C# is cooperative cancellation, not a thread abort. Pass it through async calls, check it around long CPU loops, and define whether cancelled work leaves durable side effects behind.

mediumconcept

A customer cancels a twelve-month policy after four months. How much do you refund?

It depends on who cancelled and why: pro rata returns the unused share, short rate keeps a penalty, and which applies is set by the policy wording and the jurisdiction rather than by the system. Fees are usually not refundable, and the calculation has to be reproducible years later.

hardconcept

A client hangs up halfway through a request. How do you structure a Go HTTP service so it stops doing the work?

Go context cancellation stops wasted request work when the client disconnects or a timeout expires. Pass the request context into database, HTTP and worker calls, and make goroutines return when ctx.Done closes.

mediumconcept

You run ten coroutines concurrently and one of them raises. What happens to the other nine?

With gather they keep running unsupervised and their failures may surface as an unretrieved-exception warning. A TaskGroup, added in Python 3.11, cancels the siblings, waits for them to finish unwinding, and raises an ExceptionGroup you handle with except*.

hardconcept

You stream the model's answer token by token to the browser. What does that change about error handling, guardrails and cost?

Streaming commits you to the response before you have seen it: the status code is already sent, any check that needs the whole output now runs after the user has read part of it, a mid-stream failure has no clean retry, and an abandoned tab keeps generating tokens you pay for. It also connects llm serving to the point an interviewer is testing.

hardconcept