Preparing your design workspace

Loading the problem and your latest saved attempt…

Design an In-Memory SQL Database

Design a single-server in-memory database that runs basic SQL with filters and joins, then add fast joins and ACID transactions with a write-ahead log and multiversion concurrency control.

Problem statement

Design an in-memory relational database that applications use through a small SQL dialect: CREATE TABLE, INSERT, SELECT with a WHERE filter, and JOINs. The database parses each statement, plans it, and runs it against tables held in memory.

For this exercise, assume one database server process on a machine with many CPU cores. Columns have fixed types (64-bit integer, double, string, and boolean), may hold NULL except in primary-key columns, and each table declares a primary key; a comparison with NULL is false.

A query selects a list of columns, its WHERE filter combines comparisons with AND and OR, and a join combines two tables on equal column values. A statement outside a transaction runs as its own one-statement transaction.

The workload mixes many small inserts and primary-key lookups with analytical queries that scan, filter, and join millions of rows.

For this exercise, assume the design then grows in two steps: joins between large tables must become fast, and clients must be able to change rows with UPDATE and DELETE by primary key and group several statements into one transaction with ACID guarantees, including durability across a process crash.

Secondary indexes, aggregation, user accounts, and replication to other machines are out of scope.

What to build

  1. Clients can create a table with typed columns and a primary key, and insert rows; a row with a wrong type or a duplicate primary key is rejected.
  2. Clients can select chosen columns from a table with a WHERE filter that combines comparisons using AND and OR.
  3. Clients can join two tables on an equality condition and filter the joined rows.
  4. Clients can update and delete rows by primary key and group statements with BEGIN, COMMIT, and ROLLBACK; committed changes survive a process crash, and concurrent readers see a consistent snapshot.

At scale

  • For this exercise, assume up to 200 million rows in total, with all table data fitting in 64 GB of memory on one server.
  • For this exercise, assume analytical queries scan, filter, and join up to 20 million rows and should finish in about one second, while primary-key lookups and single-row inserts finish within a few milliseconds.
  • For this exercise, assume up to 200 concurrent client sessions, and long analytical reads must not block writers.
  • For this exercise, assume a committed transaction must survive a process crash, and restart recovery should finish within a few minutes.