Mini 2: Micro-Redis
In Mini 1, you used Redis. Now you'll build one. Your task is to design and build a Redis-compatible service in Rust, on top of tokio. You only need to support a small subset of Redis commands. For pedagogical reasons, a few of the core requirements below differ from how the real Redis server behaves, sometimes quite a lot. Where our spec and real Redis disagree, follow ours.
Core Design Requirements
- Single-machine service. Assume the hardware never crashes and the software stack underneath us (OS, filesystem, and so on) behaves correctly. For now, the only thing that can go wrong is our own code.
- Multithreaded and asynchronous. The service should be asynchronous by design and use multiple threads where that makes sense. Since we're using
tokio, most of this comes for free. - Linearizable. Every request/response interaction must be linearizable under the failure assumptions above. If the service crashes, it stops and gives up. (Ideally, it shouldn't crash.)
- Multiple databases. The service keeps several independent databases (namespaces). As in real Redis, clients choose one with
SELECT. There are 16 of them, numbered 0 through 15, and the default is 0.
Wire Protocol. To be Redis-compatible, the service must speak the Redis wire protocol. We'll use protocol version 2 (RESP2).
Port. It should be possible to specify the port the service listens on, for example with a command-line flag. Default to 6379, as real Redis does.
API Specifications
Use the official Redis command reference for each command's behavior and performance guarantees, and handle errors sensibly. We only support the following commands:
- SELECT: as in the real spec, except that
SELECTmay only be called at the start of a session, right after the client connects. - GET: as in the real spec.
- SET: as in the real spec, but without options. Only the bare
SET key valueform is needed. - PING: as in the real spec.
PINGis exempt from the linearizability requirement and doesn't count toward the history. - EXISTS: as in the real spec.
- RPUSH, LPUSH: as in the real spec.
- BLPOP, BRPOP: as in the real spec, except that a single call can wait on at most 5 keys. The timeout is a floating-point number (a double), as in recent versions of Redis.
As you develop, write extensive programmatic tests to convince yourself (and us) that the service meets these requirements. Automatic linearizability checking is optional; see the extra challenge below.
Exclusionary
You do not need to support pipelining, where a client sends several commands at once and command B is queued while command A is still running. In our setting, each client sends one command and waits for its response before sending the next. (The extra credit below may change that.) You also don't need persistence: everything can live in memory, and it's fine to lose it all when the service stops.
How to hand in
- Your code, along with its build configuration (
Cargo.tomland friends). - Your tests, and a way to run them (
cargo testis perfect). - A README that explains how you keep the service linearizable, especially around the blocking commands. It should also give step-by-step instructions to start the server and talk to it (for example, with
redis-cli). We'll use it to run your service ourselves after demo day.
Getting Started & Hand-in Instructions
This mini is individual. You'll work in your own GitHub repository.
- Create a repository on GitHub for this mini, and keep it private until after your demo.
- Follow good commit and branching practices.
- Tag the version you want graded as
1.0.0. - Submit the repository's URL on the course LMS.
Demo day. You'll demo your service live, with several clients talking to it at once. Find another person to help you on the day. Once you've demoed, make the repository public so we can grade it.
Tips and Pointers:
- The tokio tutorial builds a mini Redis in Rust and is a great place to start.
Extra Credit (Optional)
Support enough Redis commands, properly, to run your Mini 1 crawler on top of your own Redis instead of the real one. Which commands you'll need depends on how you built your crawler. Implement them as in the real spec, keep them linearizable like the rest, and list them in your README. (If crawl status -f uses pub/sub, you'll either need that too or switch to polling.) Show it off on demo day.
Two things to watch out for:
- Pipelining. The
rediscrate'sMultiplexedConnectionpipelines: several tasks share one connection and send commands without waiting for each other's replies. Either support pipelining (answer each connection's commands in order), or change your crawler to use one connection per task. Your call. - Atomicity. You don't need
MULTI/EXECor Lua scripting. If your crawler relies on them, rework it to use single commands that are atomic on their own, such asSADD(check its return value) orINCR. It's fine to change your crawler however you need to, as long as it still meets the Mini 1 spec.
Extra Challenge (for No Real Credit)
This one is just cool. If you're up for it, write a linearizability checker and test your service with it. According to the Internet, Stateright is a good starting point.