Loading...
Loading...
Redis feels like a black box until you build a tiny version yourself. You start with a program that just listens on a port. By the end, the same program speaks the real Redis language, remembers data after a restart, and a backup machine quietly mirrors it. Pure Elixir on the BEAM. No Phoenix. No magic.
Engineers are learning here from
Build your own Redis in Elixir on the BEAM, one short server.exs at a time. You will write a small server that listens on a port, then teach it the same language real Redis clients speak, then give it memory, then teach it to remember after a restart, then let many readers subscribe to one writer. By the end you will have a working stand-in for Redis you understand line by line. The Elixir twist is that the actor model and binary pattern matching make several of these layers genuinely shorter than the sibling courses.
Write your own Redis in Elixir on the BEAM, one short server.exs at a time. Sockets, the wire language, the store, expiry, persistence, fan-out, and a backup machine.
What you'll ship
What you'll learn
Curriculum
Network and protocol
Open a TCP port with :gen_tcp, spawn a process per connection, parse RESP with binary pattern matching.
Store and expiry
Agent for the simple KV, then GenServer for TTL bookkeeping.
Durability: AOF and RDB on the BEAM
File.open(:append) for AOF, :erlang.term_to_binary for RDB, atomic File.rename for both.
Messaging and replication
Registry + send/2 for both pub/sub and replication. The cleanest siblings in the series.
Scaling: OTP shutdown and benchmark
trap_exit + terminate/2 gives graceful shutdown almost for free. Then measure.
Who it's for
You write Phoenix every day. You want a project that exercises gen_tcp, GenServer, Registry, OTP supervision, and binary pattern matching in one cohesive build.
You know another language. You want to see why people who learn Elixir get evangelical about the actor model.
You read about Erlang's nine-nines and want to feel the primitive that made it possible by pointing it at a stateful, networked, replicated service.
FAQ
Helpful but not required. Step 9 introduces supervisors lightly. The full Application + release shape is in the exercises.
Same architecture, dramatically less code on the messaging modules. The Registry-based pub/sub is half the LOC of any sibling. The course README compares them all side-by-side.
No, but the BEAM is faster than you might expect for IO-bound workloads. With ETS instead of GenServer, our Elixir server can land around 50-100k ops/s on this benchmark.
Phoenix is a web framework. We want to feel gen_tcp, GenServer, and OTP directly. Phoenix would hide exactly the layer we are studying.
Write your own Redis in Elixir on the BEAM, one short server.exs at a time. Sockets, the wire language, the store, expiry, persistence, fan-out, and a backup machine.