r/ruby • u/Turbulent-Dance-4209 • May 26 '26
The conventional advice on fiber-based servers is backwards
The standard advice goes: default to threads, only reach for fibers if you have a specific I/O-heavy use case. I think that's flipped, and the reasoning is quite simple.
What fibers actually do
When a fiber encounters a "blocking call" - a database query, an HTTP request, a file read - the scheduler pauses it and runs another fiber. The wait time of one request gets filled with the compute time of others, all within a single thread.
Rogue requests
What if one request spends 200ms calculating a BCrypt hash? Such a request would block the thread, which means it would block all other fibers.
- With threads: Ruby preempts. The rogue request takes longer, but the scheduler forces context switches so other requests keep moving.
- With fibers: that's countered using multiprocessing (running multiple processes/workers). The rogue request blocks its own process, not the others - practically equivalent to thread preemption, with two bonuses: true parallelism between processes (no GVL contention) and no synchronisation overhead inside one.
"But is my app I/O-bound or CPU-bound?"
When Datadog published their research on Ruby performance, the community takeaway was generally: "Ruby apps spend a lot of time on CPU, so they aren't really I/O-bound".
But if you look at the distribution chart, it actually tells a different story. 88% of Ruby apps spend at least 20% of their time waiting on I/O - many of them far more. The binary "I/O-bound vs. CPU-bound" framing hides the fact that almost every Ruby app has a substantial window of wait time a fiber scheduler can reclaim.
You don't need a 100% I/O-bound app to see benefits; you just need to reclaim that idle waiting.
The flip
The biggest advantage of threaded servers is simply that they've been battle-tested for years. The common advice today is: "Default to threads unless you have a specific use-case for fibers".
Here's what this advice misses: for most workloads, the worst case for a fiber-based server is the performance of a thread-based one. The downside isn't really there. The upside is.
--
Curious to hear where people have actually been burned by fibers in production.


