Free to read

Build your own Redis in Elixir, one short server.exs at a time

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.

Still deciding? Ask first.

Message a mentor about fit, prerequisites, or where to start. Replies come on WhatsApp, usually within a day.

  • Curriculum fit, prerequisites, or where to start
  • Honest answer, no pressure to enroll

Taught by an engineer who has shipped this

  • ISO 27001

    Led the engineering work behind the certification of a regulated EU platform.

  • Series A platform

    Architected the case-management product that became the business a €11.6M round was raised on.

  • 3x faster deploys

    Cut time-to-deploy by migrating to Kubernetes on GCP with deploy-on-merge.

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

Real projects, not toy demos.

  • A gen_tcp server with one BEAM process per connection
  • A RESP parser using binary pattern matching the compiler verifies
  • A KV store using GenServer (with an ETS upgrade path in the exercises)
  • EXPIRE / TTL / PERSIST with System.monotonic_time deadlines and lazy delete
  • AOF persistence using File.open(:append) plus a send-based replay flag
  • RDB snapshots via :erlang.term_to_binary and atomic File.rename
  • SUBSCRIBE / PUBLISH using Registry with keys: :duplicate
  • Master/replica replication via the same Registry primitive
  • Graceful shutdown via Process.flag(:trap_exit, true) and the terminate/2 callback
  • A benchmark harness that compares your Elixir server to real Redis on p50/p95/p99

What you'll learn

You finish able to:

  • Build a concurrent gen_tcp server with one process per connection
  • Parse the Redis wire format using binary pattern matching
  • Choose between Agent, GenServer, ETS, and Registry by access pattern
  • Implement TTLs and AOF-replay-safe persistence with monotonic_time and File.open
  • Snapshot in-memory state and write it atomically with File.rename
  • Wire pub/sub and replication using Registry plus send/2
  • Coordinate graceful shutdown with trap_exit and terminate/2 callbacks

Curriculum

From :gen_tcp to your own Redis.

  1. 01

    Network and protocol

    Open a TCP port with :gen_tcp, spawn a process per connection, parse RESP with binary pattern matching.

  2. 02

    Store and expiry

    Agent for the simple KV, then GenServer for TTL bookkeeping.

  3. 03

    Durability: AOF and RDB on the BEAM

    File.open(:append) for AOF, :erlang.term_to_binary for RDB, atomic File.rename for both.

  4. 04

    Messaging and replication

    Registry + send/2 for both pub/sub and replication. The cleanest siblings in the series.

  5. 05

    Scaling: OTP shutdown and benchmark

    trap_exit + terminate/2 gives graceful shutdown almost for free. Then measure.

Who it's for

Is this for you?

Elixir developers

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.

Backend engineers exploring Elixir

You know another language. You want to see why people who learn Elixir get evangelical about the actor model.

BEAM enthusiasts

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

Common questions.

  • Do I need OTP supervision experience?

    Helpful but not required. Step 9 introduces supervisors lightly. The full Application + release shape is in the exercises.

  • How does it compare to the Python, Go, Node, Rust, Ruby siblings?

    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.

  • Will my Elixir server beat real Redis?

    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.

  • Why not start with Phoenix?

    Phoenix is a web framework. We want to feel gen_tcp, GenServer, and OTP directly. Phoenix would hide exactly the layer we are studying.