Good engineers don't open the code editor first. They decide what to build and how, so the code is easy to write. In this chapter you'll plan DevTinder like a real team: requirements, high-level design, database design and the complete list of APIs.
In this chapter you'll learn
- how to turn an idea into a feature list (requirements)
- what HLD and LLD are, and what goes in each
- how to design DevTinder's database collections
- what REST is, and the rules for designing REST APIs
PUTvsPATCH, idempotency and stateless APIs- the full list of DevTinder APIs you'll build in Season 2
Before you start: read Chapter S2 01: Microservices vs Monolith - How to build a project (the SDLC).
Step 1: Requirements: what are we building?
DevTinder is like Tinder, but for developers: you browse other developers' profiles and connect with the ones you'd like to collaborate with.
Features (functional requirements)
- Accounts: sign up, log in, log out.
- Profile: view and edit your profile (name, age, gender, photo, about, skills), change password.
- Feed: see developer profiles one at a time, excluding people you've already interacted with.
- Connection requests: on a profile, choose Interested (send a request) or Ignore (skip them).
- Review requests: see requests sent to you; accept or reject them.
- Connections: see everyone you're connected with (requests that were accepted).
Non-functional requirements
- Passwords must be stored securely (hashed: Chapter S2 09: Encrypting Passwords).
- Only logged-in users can use the app (authentication: Chapter S2 10: Authentication, JWT & Cookies).
- The feed must stay fast with many users (pagination: Chapter S2 14: Building Feed API and Pagination).
Step 2: High-Level Design (HLD)
The HLD is the big picture: which parts the system has, which technologies they use, and how they talk to each other. A non-engineer should be able to follow it.
Tech stack: MERN
- MongoDB: database (Chapter 12: Databases SQL and NoSQL, Chapter 13: Creating a database & mongodb)
- Express: backend framework on Node.js (Chapter S2 03: Creating our Express server)
- React: frontend (Chapter S2 15: DevTinder UI - Part 1)
- Node.js: runs the backend
Architecture
Two separate applications: a React frontend in the browser and a Node.js/Express backend API. The frontend never touches the database; it calls the backend's APIs, and the backend talks to MongoDB. (As Chapter S2 01: Microservices vs Monolith - How to build a project explained, this is a client–server split; the backend itself is a monolith.)
Step 3: Low-Level Design (LLD)
The LLD zooms in: exact database schemas, API endpoints with their inputs and outputs, and the main logic. It's what developers follow while coding.
Database design
DevTinder needs just two collections.
users: one document per person:
| Field | Type | Notes |
|---|---|---|
firstName | String | required, 3–50 characters |
lastName | String | |
emailId | String | required, unique, lowercase |
password | String | required; stores a hash, never the real password |
age | Number | minimum 18 |
gender | String | one of male, female, others |
photoUrl | String | a valid URL, with a default image |
about | String | short bio, with a default |
skills | Array of Strings | e.g. ["Node.js", "React"] |
createdAt, updatedAt | Date | added automatically |
connectionrequests: one document per request between two users:
| Field | Type | Notes |
|---|---|---|
fromUserId | ObjectId → users | who sent it |
toUserId | ObjectId → users | who received it |
status | String | one of ignored, interested, accepted, rejected |
createdAt, updatedAt | Date | added automatically |
Why a separate collection for requests instead of an array inside each user? A user could receive thousands of requests. Unbounded arrays make documents huge, and a request involves two users, so neither "owns" it. A separate collection with references to both users is cleaner. You'll build these schemas in Chapter S2 06: Database, Schema, Models & Mongoose and Chapter S2 12: Logical DB Query and Compound Indexes.
The status field moves through a small set of states:
interestedorignored: set by the sender when swipingacceptedorrejected: set by the receiver when reviewing aninterestedrequest
Step 4: API design with REST
What is a REST API?
An API (Application Programming Interface) is a set of rules for how two programs talk to each other. A web API lets a client (the React app, Postman, a mobile app) talk to your server over HTTP.
REST (REpresentational State Transfer) is the most common style for designing web APIs. Its main ideas:
- Resources are the things in your app (users, requests, connections), each identified by a URL:
/users/42. - HTTP methods say what to do with them (
GETreads,POSTcreates...). - Stateless: every request carries everything the server needs to handle it (including who you are, usually as a token). The server doesn't remember earlier requests. This makes servers easy to scale: any server can handle any request.
- Representations: data travels in a standard format, almost always JSON.
- Status codes tell the client what happened (
200OK,201Created,404Not Found...; full list in Chapter S2 05: Middlewares and Error Handlers).
HTTP methods
| Method | Meaning | Example |
|---|---|---|
GET | read data | GET /profile/view |
POST | create something / perform an action | POST /signup |
PUT | replace a resource completely | PUT /users/42 with the full user |
PATCH | partially update a resource | PATCH /profile/edit with { "about": "..." } |
DELETE | delete | DELETE /users/42 |
PUT vs PATCH
Imagine the stored profile { name: "Akshay", city: "Dehradun", age: 30 }, and you send { age: 31 }:
- with
PATCH, the result is{ name: "Akshay", city: "Dehradun", age: 31 }: onlyagechanged. - with
PUT, the body is the new resource:{ age: 31 };nameandcityare gone.
So PUT expects the complete resource; PATCH sends just the changes. DevTinder's profile edit is a PATCH.
Idempotency
An operation is idempotent if doing it many times has the same effect as doing it once.
GET,PUTandDELETEare idempotent: deleting user 42 twice leaves user 42 deleted.POSTis not: sendingPOST /signuptwice tries to create two accounts.PATCHcan go either way:{ age: 31 }is idempotent, but "add 1 to age" is not.
This matters for retries: if a network error hides whether a request succeeded, a client can safely resend an idempotent request.
REST naming conventions
- Use nouns for resources, not verbs:
/users, not/getUsers(the method already says "get"). - Use plural collection names:
/users,/users/42. - Nest to show relationships:
/users/42/connections. - Use query strings for filtering and pagination:
/user/feed?page=2&limit=10.
(DevTinder's routes, like /request/send/:status/:toUserId, follow the course's style rather than strict REST naming. That's common in real projects too; consistency matters more than purity.)
Step 5: DevTinder's API list
These are the APIs you'll build in Season 2, grouped by feature. Each group becomes an Express router (Chapter S2 11: Diving into the APIs and Express router).
authRouter
| Method & path | What it does | Chapter |
|---|---|---|
POST /signup | create an account | Chapter S2 07: Diving into APIs, Chapter S2 09: Encrypting Passwords |
POST /login | check email + password, set a JWT cookie | Chapter S2 10: Authentication, JWT & Cookies |
POST /logout | clear the cookie | Chapter S2 11: Diving into the APIs and Express router |
profileRouter
| Method & path | What it does |
|---|---|
GET /profile/view | get the logged-in user's profile |
PATCH /profile/edit | update allowed profile fields |
PATCH /profile/password | change password |
requestRouter
| Method & path | What it does | Chapter |
|---|---|---|
POST /request/send/:status/:toUserId | status = interested or ignored | Chapter S2 12: Logical DB Query and Compound Indexes |
POST /request/review/:status/:requestId | status = accepted or rejected | Chapter S2 13: ref, Populate and Thought Process of writing API's |
userRouter
| Method & path | What it does | Chapter |
|---|---|---|
GET /user/requests/received | pending requests sent to me | Chapter S2 13: ref, Populate and Thought Process of writing API's |
GET /user/connections | everyone I'm connected with | Chapter S2 13: ref, Populate and Thought Process of writing API's |
GET /user/feed | profiles to show me, paginated | Chapter S2 14: Building Feed API and Pagination |
:status, :toUserId and :requestId are route parameters: placeholders filled from the URL, which you'll read with req.params (Chapter S2 04: Routing and Request handlers).
Key takeaways
- Start with requirements (functional and non-functional) before code.
- HLD = the big picture (architecture, tech stack); LLD = the details (schemas, endpoints, logic).
- DevTinder uses MERN and two collections:
usersandconnectionrequests. - REST: resources as URLs, HTTP methods as actions, stateless requests, JSON, status codes.
- PATCH updates part of a resource; PUT replaces it completely.
- Idempotent = repeating it has the same effect: GET, PUT, DELETE yes; POST no.
Interview questions
Q1. What is a REST API?
A REST API is a web API designed in the REST architectural style: resources are identified by URLs, clients act on them with standard HTTP methods (GET, POST, PUT, PATCH, DELETE), requests are stateless (each carries all needed information), data is exchanged in a standard format (usually JSON), and responses use HTTP status codes.
Q2. What is the difference between PUT and PATCH?
PUT replaces the whole resource with the request body; fields you leave out are removed. PATCH partially updates the resource, changing only the fields sent. PUT is idempotent; PATCH may or may not be, depending on the operation.
Q3. What does idempotent mean? Which HTTP methods are idempotent?
An operation is idempotent if performing it several times has the same effect on the server as performing it once. GET, HEAD, PUT, DELETE and OPTIONS are idempotent; POST is not; PATCH is not guaranteed to be. Idempotency makes retries after network failures safe.
Q4. What does "stateless" mean in REST?
The server keeps no client session state between requests. Each request must include everything needed to process it, including authentication (for example a JWT in a cookie or header). Stateless servers are easier to scale, since any server instance can handle any request.
Q5. What is the difference between HLD and LLD?
High-Level Design describes the overall architecture: main components, how they interact, technology choices, data flow. Low-Level Design describes how each component is built: database schemas, API contracts, classes and functions, validation rules and edge cases.
Q6. How would you design the database for a Tinder-like app?
A users collection for profiles, and a separate connectionRequests collection with fromUserId, toUserId (references to users) and a status restricted to a fixed set of values (interested, ignored, accepted, rejected), plus timestamps. Add a compound index on fromUserId + toUserId for fast duplicate checks (Chapter S2 12: Logical DB Query and Compound Indexes). Keeping requests separate avoids huge, ever-growing arrays inside user documents.
Q7. What are good REST URL naming practices?
Use plural nouns for resources (/users, /users/42), not verbs; let the HTTP method express the action; nest for relationships (/users/42/orders); use query parameters for filtering, sorting and pagination (?page=2&limit=10); keep URLs lowercase and consistent; and version public APIs (/api/v1/...).
What's next
The plan is ready. In Chapter S2 03: Creating our Express server you'll create the backend project: npm init, package.json, installing Express, and your first Express server.