From 150,000 OS Threads to C++20 Coroutines: A 1000x Memory Reduction
A Practical Intuition for C++20 Coroutines

At YDB, benchmarking a distributed database with TPC-C initially required 150,000 OS threads and 600 GiB of RAM, saturating the client before the database. After optimizing Java virtual threads and hitting a deadlock, the team rewrote the client in C++ using futures and then coroutines. The result: 16 worker threads, memory reduced by over 1000x, and a client that keeps up. This post explores the journey, explains coroutine internals, and tackles the key question of which thread executes continuations after a future or coroutine becomes ready.
OS threads are a good unit of parallel execution. They are a poor unit for representing hundreds of thousands of mostly sleeping workflows.