Dart (3.13) Module 12
Concurrency with isolates interview questions
Interview questions on concurrency with isolates: short warm-ups, then what each harder question tests, the first step of a good answer and its follow-ups.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
In what ways does a Dart isolate differ from a thread in Java or C++?
Answered in the lesson Isolates and Isolate.run for heavy work
-
Fresher
Why does marking a CPU-heavy function async not keep an app responsive?
Answered in the lesson Isolates and Isolate.run for heavy work
-
Fresher to mid
What do a SendPort and a ReceivePort each do in a two-isolate program?
Answered in the lesson Long-lived isolates, SendPort and ReceivePort
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
A nightly Dart job reads 12 monthly sales files, parses them and merges the totals. It takes 48 minutes in one isolate, and parsing is 75 % of that time. The server has 8 cores. How many isolates would you use, what run time do you expect, and what limits it?
- What it tests
- Applying Amdahl's law to real numbers, knowing what isolates cost in start-up, memory and copies, and checking that a split job still gives the same totals.
- First step
- Separate what can run in parallel, parsing the 12 files, from what cannot, reading the list and merging, and put minutes on both: 36 minutes of parsing and 12 minutes of everything else. Only then choose a number of isolates.
- Follow-ups
-
- Why not start 12 isolates, one per file?
- What does sending each file's parsed rows back to the main isolate cost?
- How do you show that the split job gives the same totals as before?
From the lesson Isolates and Isolate.run for heavy work
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 4 minutes
-
Mid to senior
Your Dart package checks uploaded images inside Isolate.run so that apps stay responsive. A team now builds it for the web with dart compile js, and every check fails with UnsupportedError. Why, and how do you change the package so that native and web users both get a working check?
- What it tests
- Knowing that the web platform has no isolates, choosing between conditional imports, web workers and work split into short steps on the main thread, and keeping one API on every platform.
- First step
- Find where the error comes from: Isolate.run creates a RawReceivePort for its result, which the JavaScript platform does not implement, so the call fails when it runs. The package needs one public function with a native and a web implementation behind it.
- Follow-ups
-
- How does a conditional import choose the implementation?
- When is it acceptable to run the check on the main thread on the web?
- What does a web worker version need that the isolate version does not?
From the lesson Isolates and Isolate.run for heavy work
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A Dart image service sends resize jobs to four worker isolates, and all replies come back to one ReceivePort in main. Under load, a few customers receive another customer's thumbnail. What is wrong in the protocol, and how do you fix it so that a slow or crashed worker cannot confuse or block callers?
- What it tests
- Matching replies to requests across isolates, request ids with Completers, handling replies that arrive out of order, and failing the requests of a worker that dies.
- First step
- Look at how a reply finds its caller: what in the reply says which request it answers, and what changes under load, when small and large images are resized at the same time.
- Follow-ups
-
- Why do the mix-ups appear only under load?
- What happens to the callers of a worker that crashes in the middle of a job?
- How should jobs be spread over the four workers?
From the lesson Long-lived isolates, SendPort and ReceivePort
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A Dart command-line tool spawns two worker isolates, prints report done, and then its CI step keeps running until the job's 60-minute limit. How do you find what keeps it alive, and how do you make every run end on time?
- What it tests
- Knowing what keeps a Dart program running, closing ports and stopping workers in order, and a shutdown that cannot hang on a worker that does not answer.
- First step
- List what the main isolate still holds after it prints: open ReceivePorts, timers that repeat, stream listeners and open files. Any one of them can keep a Dart program running after its work is done.
- Follow-ups
-
- Why did the tool not end when main returned?
- In what order should the workers and ports be shut down?
- What should the tool do if a worker never answers the stop message?
From the lesson Long-lived isolates, SendPort and ReceivePort
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
A Dart server receives 200 MB video uploads and sends each to a long-lived worker isolate that computes a SHA-256 checksum. Under load, memory use doubles and the main isolate stalls for tens of milliseconds per upload. What causes both, and how should the bytes reach the worker?
- What it tests
- Knowing that SendPort.send copies the whole message, what TransferableTypedData and Isolate.exit change, and when to send a path or a stream of chunks instead of bytes.
- First step
- Measure what one upload costs on the main isolate's side: how long each send takes, and the memory in use before and after it. Those two numbers show whether the bytes are being copied, and where.
- Follow-ups
-
- What does TransferableTypedData change, and what does it not?
- Why not send the worker the path of a temporary file instead?
- How should the worker return a large result, if it had one?
From the lesson Long-lived isolates, SendPort and ReceivePort
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes