The Actor Model on Ruby: A Side-by-Side Look at Ractor and Elixir/OTP (Part 1)
How the actor model is getting it's place on Ruby
As a Ruby engineer, I’ve spent years watching the concurrency conversation with a mix of curiosity and resignation. We had threads, but the GVL kept them on a leash. We had forking, but it ate memory for breakfast. Then Elixir came along and showed everyone what the actor model could do when the VM was built for it from day one.
But Ruby isn’t sitting still. Ractor is here, and it’s no longer just an experimental curiosity. So let’s do what we do best: roll up our sleeves, write some code, and compare the two approaches side by side.
This isn’t a “which is better” piece. It’s a technical dive for engineers who want to understand the tradeoffs at a fundamental level.
The Core Primitives: Processes vs. Ractors
In Elixir, the actor is the process. It’s a lightweight, isolated unit of execution managed by the BEAM VM. You can spawn millions of them. They don’t share memory; they communicate exclusively via message passing.
In Ruby, the actor is the Ractor (Ruby Actor). It provides true parallelism by giving each Ractor its own GVL (or bypassing it entirely), meaning multiple Ractors can run Ruby code on multiple cores simultaneously. But unlike BEAM processes, Ractors are backed by native OS threads, and you can’t spawn millions of them. They’re heavier.
Here’s the simplest possible actor in both worlds:
Elixir:
pid = spawn(fn ->
receive do
{:hello, name} -> IO.puts("Hello, #{name}!")
end
end)
send(pid, {:hello, "CTO"})
Ruby:
ractor = Ractor.new do
msg = Ractor.receive
puts "Hello, #{msg}!"
end
ractor.send("CTO")
The API looks deceptively similar. But the semantics underneath are worlds apart.
State and Isolation: The Frozen Reality
This is where the Ruby engineer’s brain needs to rewire itself.
Elixir processes are naturally isolated. Every process has its own heap. Sending a message copies the data (for immutable terms) or transfers it (for large binaries). You never worry about shared mutable state because there is none.
Ractors enforce isolation through shareability rules. A Ractor can only access objects that are “shareable”: meaning deeply frozen and immutable. If you try to pass a mutable object to a Ractor without explicitly copying or moving it, Ruby raises a Ractor::IsolationError.
Let’s see this in practice. Here’s a constant that works, and one that explodes:
# This will raise an error in a Ractor
BAD = { msgs: ["mutable"] }.freeze
Ractor.new { BAD[:msgs].first }.value
# => Ractor::IsolationError
# This works because it's deeply frozen
GOOD = Ractor.make_shareable({ msgs: ["immutable"] })
Ractor.new { GOOD[:msgs].first }.value
# => "immutable"
The Ractor.make_shareable method recursively freezes the object graph. In a Rails app, this means your constants, your configuration, and anything you want to access across Ractors needs to be deeply frozen.
In Elixir, you never think about this. You just pass data.
Building a Server: GenServer vs. A Ractor Loop
Elixir’s GenServer is the workhorse abstraction. It wraps a process with a receive loop, handles synchronous calls, asynchronous casts, and state management in a clean callback structure.
Let’s build a simple counter server in both.
Elixir GenServer:
defmodule Counter do
use GenServer
def start_link(initial) do
GenServer.start_link(__MODULE__, initial, name: __MODULE__)
end
def increment, do: GenServer.cast(__MODULE__, :increment)
def get, do: GenServer.call(__MODULE__, :get)
@impl true
def init(initial), do: {:ok, initial}
@impl true
def handle_cast(:increment, state) do
{:noreply, state + 1}
end
@impl true
def handle_call(:get, _from, state) do
{:reply, state, state}
end
end
The GenServer gives you a mailbox, a state that’s implicitly threaded through callbacks, and a supervision-friendly interface.
Ruby Ractor (Actor-style):
class Counter
def initialize(initial)
@ractor = Ractor.new(initial) do |state|
loop do
msg = Ractor.receive
case msg
in [:cast, :increment]
state += 1
Ractor.yield(:ok)
in [:call, :get, reply_to]
reply_to.send(state)
end
end
end
end
def increment
@ractor.send([:cast, :increment])
@ractor.take
end
def get
reply_ractor = Ractor.current
@ractor.send([:call, :get, reply_ractor])
Ractor.receive
end
end
Notice the difference. The Ractor version requires you to manually manage the reply channel for synchronous calls. There’s no built-in call/cast distinction. You’re building the protocol yourself. This is exactly the kind of thing GenServer abstracts away.
You could build a GenServer-like framework on top of Ractors. In fact, early experiments did exactly that. But as the Elixir community will tell you, the power of OTP isn’t just GenServer. It’s the supervision tree.
Supervision: The Elephant in the Room
Elixir’s “let it crash” philosophy works because of supervisors. When a GenServer crashes, a supervisor restarts it with a known initial state. The system self-heals.
Ractors have no built-in supervision. If a Ractor raises an exception, it propagates to the caller via Ractor#take or Ractor#value. You can rescue it, but there’s no automatic restart strategy. You would need to build that orchestration yourself.
For a Rails application, this is a significant gap. A background job processor built on Ractors would need its own supervision logic to handle crashes gracefully. The BEAM gives you this for free; Ruby gives you the primitives to build it, but the building is on you.
Where Ractors Shine: Parallelism Without Forking
Here’s the exciting part for Rails engineers.
The traditional way to get CPU parallelism in a Rails app is to fork Puma workers. Each worker gets its own copy of the app, its own GVL, and its own memory footprint. For a large app, eight Puma workers can consume gigabytes of RAM.
Ractors offer a different path: parallelism within a single process, without forking. Because Ractors share the same process memory space (for shareable objects) but have isolated heaps for their own work, a pool of Ractors can use less memory than a cluster of forked workers.
This is the promise of Ractors: true multi-core parallelism with a smaller memory footprint, right inside your existing Rails process.
When to Reach for Which
After all this, here’s my pragmatic take as a Ruby engineer:
Reach for Ractors when:
- You have CPU-bound work in a Rails app (image processing, data crunching, complex serialization) that you want to parallelize without forking.
- You’re memory-constrained and want to reduce worker count.
- You’re building a new service and want to experiment with actor patterns without leaving Ruby.
Reach for Elixir/OTP when:
- Concurrency and fault tolerance are the core architectural requirements.
- You need millions of lightweight processes (websocket connections, IoT devices, chat sessions).
- You want supervision, hot code reloading, and distribution for free.
- You’re building a system where “let it crash” is the right philosophy.
The Ruby community’s adoption of the actor model isn’t about beating Elixir at its own game. It’s about making Ruby better at the problems Ruby engineers already face. As one Elixir Forum member put it, this is “beneficial cross-pollination between languages, not a competition”.
Ractors are not Erlang processes. They never will be. But they’re a powerful new tool in the Ruby toolbox, and for a CTO building Rails systems at scale, that’s something worth getting excited about.
The actor model has finaly arrived on mainstream Ruby. It’s time to start experimenting stuff with it.
2026 REFRESH Things evolved and Ruby 4.0 brough fundamental changes in the way Ractors work so I decided to write a Part 2 of the present article, making it a serie in the end.