The Good, The Bad, and the Ugly: A Journey from this synchronized to Asynchronous Code
summary
A legacy Scala blockchain codebase with pervasive synchronized blocks and deadlocks is refactored incrementally into functional async using cats-effect 2 -> cats-effect 3, migrating synchronous locks to IO/Resource/Ref/fibers/supervisor patterns and separating CPU, blocking and sync thread pools. Context-shift gymnastics disappear, blocking ops hop to an internal pool, and graceful shutdown uses supervisors. Results: deadlocks vanish, average CPU drops from 20% → 2–3%, and the pipeline handles up to 80k tx/s in testing.
AI-written summary · about
chapters (18)
- 0:00Journey introduction
- 1:15Blockchain project challenge
- 4:04Synchronized code nightmare
- 6:13Synchronized swamp
- 8:01Manual sync fails
- 10:09Cats Effect IO
- 12:22Concurrency vs parallelism
- 14:49Shared resources safely
- 17:23Thread-safe state with Ref
- 20:19Fibers in Cats Effect
- 23:15Threadpool juggling
- 25:46Thread pool assignment
- 27:11Year-long threadpool struggle
- 27:55Refactoring tangled code
- 28:59Cats Effect 3 shift
- 31:25Fire-and-forget tasks
- 32:54Supervisors for fibers
- 33:58Remarkable efficiency
related talks
40mCats Effect 3
29mAsychronous programming in Rust
31mPick a (Effect) Lane: A comparison of direct-style Scala vs effect systems
43mThe Design of the Scalaz 8 Effect System
01h 05mLawful Asynchronous Programming
36mConcurrency with Cats-effect
01h 35mThinking Outside the Synchronisation Quadrant
51mThe Need for Async
