Introduction

Build real-world software by coding from scratch. If you can build a Redis server, you can build almost any software beyond CRUD! Because it teaches you 3 fundamental skills:

  • Network programming. The next level of programming is programming for multiple machines. Think HTTP servers, RPCs, databases, distributed systems.
  • Data structures. Redis is the best example of applying data structures to real-world problems. Why stop at theoretical, textbook-level knowledge when you can learn from production software?
  • Low-level C. C was, is, and will be widely used for systems programming and infrastructure software. It’s a gateway to many low-level projects.

Why from scratch? A quote from Richard Feynman: “What I cannot create, I do not understand”. You should test your learning with real-world projects!

Why a book? The real Redis project is a large code base built with lots of effort. The book distills the core concepts and guides you through small steps.

Table of Contents

Part 1. Redis from 0 to 1

  1. Introduction
  2. Socket Programming
  3. TCP Server and Client
  4. Request-Response Protocol
  5. Concurrent IO Models
  6. Event Loop (Part 1)
    Event Loop (Part 2)
  7. Key-Value Server

Part 2. Advanced Topics

  1. Hashtables (Part 1)
    Hashtables (Part 2)
  2. Data Serialization
  3. Balanced Binary Tree
  4. Sorted Set
  5. Timer and Timeout
  6. Cache Expiration with TTL
  7. Thread Pool

Source Code

https://build-your-own.org/redis/src.tgz

PDF/EPUB and Paperback Editions

The full book is free in web version.
You can purchase the book if you find the book helpful.

Book Cover

I have curated a list of books that are highly relevant for people who intend to DIY their own Redis.

Beej’s Guide to Network Programming.
[Amazon] [Web]
A comprehensive guide and reference to network programming. It’s a great supplement for coding your own networked apps, as the Redis book doesn’t cover all the details of socket programming.
The Linux Programming Interface by Michael Kerrisk.
[Amazon] [Web]
The socket API is only a subset of the Linux API interface. You will probably need to become familiar with the other parts, such as IOs, threads and processes, signals, and etc, if you are developing apps for Linux.
The C Programming Language by K&R.
[Amazon]
Are you scared of C, but still want to follow the project? No problem. This classic book is great for picking up C quickly, whether you are a beginner or an experienced developer.