Machine Coding Question: In-Memory SQL-Like Database
Design an in-memory SQL-like database — Razorpay’s classic Machine Coding question: tables, schema, CRUD, validation, indexing and locking with example usage.
In this article, I want to give you a glimpse of what a machine coding question might look like. This question is one of the most popular ones asked in Razorpay interviews and serves as a great starting point for preparing for machine coding challenges. While the thought process behind addressing this question can come naturally, implementing the solution can be quite challenging.
The machine coding round typically involves solving a design problem within a few hours, where candidates are required to create a clean, modular, and extensible solution based on a specific set of requirements.
Objective
The primary objective of this project is to design and implement an in-memory SQL-like database that supports a range of functionalities. The database should be capable of managing tables and records efficiently while enforcing data integrity through validation rules.
Functional Requirements
Requirements are split into three tiers so you know what to prioritize under time pressure: build first, build if time allows, and discuss only.
Part 1 — Basic Requirements
Core functionality you must build and get working first.
1. Table Management
2. Column Constraints
3. Data Operations
4. Validation
The system must raise errors during schema validation to catch issues like null values or out-of-range integers.
Part 2 — Bonus Features
Extensibility checks — can your design handle change without a rewrite.
Part 3 — Future Features
Discuss-only evolution — how the system could grow next.
Example Usage: Full Walkthrough
Here's how an interviewer would run through the flow end-to-end, one operation at a time.
1. Create a table
createTable("employees", {
name: { type: "string", required: true, maxLength: 20 },
age: { type: "int", required: true, min: 18, max: 60 },
department: { type: "string", required: false, maxLength: 20 }
})
2. Insert valid records
insert("employees", ["Alice", 30, "Engineering"]) // ok
insert("employees", ["Bob", 45, "Marketing"]) // ok
3. Insert invalid records — trigger validation
insert("employees", ["Charlie", 17, "Sales"]) // → error: age < 18
insert("employees", ["Diana", 65, "HR"]) // → error: age > 60
4. Print all records
printAll("employees")
5. Filter with a query
query("employees", { department: "Engineering" })
6. Drop the table
dropTable("employees")
Alice and Bob persist; Charlie and Diana are rejected. query({ department: "Engineering" }) returns only Alice.