Skip to content
tezvyn:

Concurrency

183 bites tagged Concurrency — interview questions with model answers, and 60-second explainers.

Android & Kotlin2 min read

Explain the difference between launch and async in Kotlin Coroutines

This tests scope behavior and side effects versus results. A strong answer says launch returns a Job for side effects, async returns a Deferred for results, and both are scope children. A red flag is using async for all tasks or ignoring exception handling.

Android & Kotlin2 min read

How does coroutine cancellation work internally?

Tests your grasp of cooperative cancellation. A good answer explains that `cancel()` sets a flag, `suspend` functions check it and throw `CancellationException`, and non-suspending loops need manual `isActive` checks.

Android & Kotlin2 min read

What is a CoroutineDispatcher and when do you use each type?

Tests your grasp of coroutine threading. A dispatcher manages which threads a coroutine runs on. Explain `Main` for UI, `Default` for CPU-intensive work, and `IO` for blocking operations. A red flag is mixing up `IO` and `Default` or using `Unconfined`.

Android & Kotlin2 min read

Structured Concurrency in Kotlin Coroutines

Tests your understanding of coroutine lifecycles and error handling. A good answer defines the parent-child relationship, then explains how cancellation and exceptions propagate through the scope. A red flag is simply calling it a way to 'group' coroutines.

Android & Kotlin2 min read

What is a `suspend` function in Kotlin?

Tests your grasp of Kotlin's core concurrency primitive. A `suspend` function can pause and resume. It must be called from another suspend function or a coroutine builder.

Android & Kotlin2 min read

Difference between launch and async in Kotlin Coroutines

This tests your grasp of coroutine result handling and exception propagation. Explain that `launch` is fire-and-forget (returns `Job`), while `async` is for results (returns `Deferred`). Mention `async` defers exceptions until `await()`.

Android & Kotlin2 min read

How does coroutine cancellation work internally?

This tests your grasp of cooperative cancellation. Explain that `cancel()` sets a flag, causing a `CancellationException` at the next suspension point. A non-suspending loop must explicitly check `isActive` to stop.

Android & Kotlin2 min read

What is a CoroutineDispatcher and when to use IO vs Default?

Tests your grasp of thread pool strategy for CPU vs. I/O-bound tasks. A good answer defines Dispatchers, contrasts the fixed-size Default pool (for CPU work) with the larger IO pool (for blocking I/O), and gives clear examples.

Android & Kotlin2 min read

Explain Structured Concurrency in Kotlin Coroutines

Tests your grasp of coroutine lifecycle management. A great answer defines the parent-child relationship within a CoroutineScope, explains cancellation propagation, and details how exceptions cancel the entire hierarchy.

Android & Kotlin2 min read

What is a Kotlin `suspend` function and how does it work?

Tests your grasp of Kotlin's non-blocking concurrency. A great answer defines a suspend function as pausable, states its two calling rules (from another suspend function or coroutine builder), and mentions the compiler's CPS transformation.

Android & Kotlin2 min read

Explain launch vs. async in Kotlin Coroutines

Tests your grasp of structured concurrency, return values, and exceptions. `launch` is for fire-and-forget tasks (returns `Job`), while `async` is for tasks that produce a result (returns `Deferred`).

Android & Kotlin2 min read

Kotlin's Job: A Handle to a Background Task

A Job is a handle to a coroutine, letting you manage its lifecycle. You get one from `launch` to control background tasks like network calls. The key footgun: a child's *failure* (Exception) cancels its parent, but a child's *cancellation* does not.

TypeScript & Web APIs2 min read

Shared Workers: One Background Script for Multiple Tabs

A SharedWorker is a single background script shared across multiple tabs or windows from the same origin. Use it to manage a single WebSocket connection or sync state between pages. The footgun: each tab must call `port.start()` on its own message port.

React & Next.js2 min read

React's Internal Scheduler Package

React's scheduler is an internal traffic cop that breaks up rendering work to keep the UI from freezing. It's used to prioritize updates and yield to the browser, but its public API is unstable and not for direct use in your app.

React & Next.js2 min read

React Fiber: Making UI Rendering Interruptible

React Fiber treats rendering like a cooperative scheduler. It breaks UI updates into small, pausable chunks, preventing long, blocking tasks. This lets high-priority work like user input interrupt heavy rendering, keeping animations and gestures smooth.

React & Next.js2 min read

useSyncExternalStore: Safely Read from External State

useSyncExternalStore lets your React components safely subscribe to data outside of React's state. Use it to connect to state libraries like Zustand or browser APIs. The main footgun: your `getSnapshot` function must return an immutable, cached value.

React & Next.js2 min read

useTransition: Keep Your UI Responsive During State Changes

useTransition lets you update state without blocking the UI, keeping your app responsive. Use it for slow renders like filtering large lists, while the `isPending` flag shows a loading state.

Python & FastAPI2 min read

Debugging Python's Asyncio

Debugging asyncio is about finding what's blocking the single-threaded event loop. Use its debug mode to detect slow callbacks and `run_in_executor` to offload CPU-bound work. The biggest mistake is calling blocking code directly, which stalls the entire app.

Python & FastAPI2 min read

asyncio Event Loop Policies: A Deprecated Pattern

Think of an event loop policy as the global factory for asyncio's event loops, controlling which loop is created and how it's retrieved. It was used to swap implementations, but the entire API is deprecated in Python 3.14 and will be removed in 3.16.

Python & FastAPI2 min read

Python's Asyncio Subprocesses: Non-Blocking Shell Commands

Run external commands without blocking your async app's event loop. `asyncio.create_subprocess_shell` lets you launch processes and await their results, keeping your server responsive.

Python & FastAPI2 min read

asyncio Queues: Coordinating Asynchronous Tasks

An asyncio queue is a channel for coroutines to safely exchange data. It's ideal for producer-consumer patterns, like a web crawler feeding URLs to parsers. The main footgun: it's not thread-safe and must be used within a single event loop.

Python & FastAPI2 min read

Coordinating Asyncio Tasks with Locks and Events

asyncio sync primitives are traffic signals for coroutines, preventing collisions over shared state. Use a Lock for exclusive access or an Event to signal multiple tasks to proceed. Footgun: these are for asyncio tasks only, not OS threads.

Python & FastAPI2 min read

The asyncio Event Loop: One Thread, Many Tasks

The asyncio event loop is a manager for a single-threaded process, juggling tasks to prevent idleness during slow I/O. It's the core of apps like FastAPI, handling network requests efficiently. The footgun is interacting with it directly; use `asyncio.run()`.

Python & FastAPI2 min read

The Python GIL: One Thread at a Time

The Python Global Interpreter Lock (GIL) is a mutex ensuring only one thread executes Python bytecode at a time. This serializes CPU-bound threads, but the lock is released during I/O, making it effective for network-bound tasks.

Get Concurrency bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.