Food Delivery App System Design: Which Database?

Choose databases for a food delivery app like Swiggy or DoorDash: orders, menus, live rider location, search and payments, each by its access pattern.

Related chapters

Keep learning

Overview

A restaurant has one till, a printed menu in the window, a search box on the street, and riders moving on a map. The till is the only place that can take money. The menu in the window can be a minute old. The map is a different machine, because riders move every few seconds and the till must not stop to record that. Start with one relational database for orders and money, because they need one transaction. Add a cache for menus, a search index fed by change events, and a geo index for riders, each when a measurement says the primary is hurting. transaction for order + wallet jobs, each with its own store search may lag behind every few s each rider location write Naming one database for everything, whether “Postgres” or “NoSQL”. The jobs have different reads, writes and freshness rules. The server crashed after the customer tapped Pay. Did we charge twice? (An idempotency key on the order and the processor call.)

Day one is one relational database

The first job is the order. Debiting a wallet and inserting the order are one transaction when both rows live in the same Postgres (or MySQL) database: both commit, or neither does. A card payment is a different system. Write the order as pending with an idempotency key, call the processor with that same key, and a unique constraint on the key makes the retry the same order. The longer Uber Eats cut of this short asks exactly that follow-up: the server crashed after the customer tapped Pay. One order, four jobs, four stores Why it is separate Order, money, address Relational primary A transaction, a unique idempotency key, a status the rider update can win or lose Menu at dinner rush Cache, key restaurant id, with a TTL The menu is read far more often than it changes. Checkout still reads the price from the primary Search index, inverted and fuzzy A derived copy. A new dish can be on the restaurant page and missing from search for a few seconds Riders within 3 km Geo index (cells, or a GEO set) Locations are a write stream. They must not land in the orders table

The follow-ups the longer cut asks

The menu cache expires under the rush. Every app server rebuilds the same menu on the database that is also taking orders. That is the Search runs behind on purpose. The inverted index is built by a consumer of menu changes. Updating it inside the order transaction would make checkout wait on a second system, and a failed index write would roll back a real order. The restaurant page reads the primary. Search is allowed to be seconds late. Postgres can do the other jobs while you are small. Trigram search and a geo index exist in Postgres. Use them until a measurement says otherwise: location writes evicting order pages from the buffer pool, search relevance you cannot get from trigrams, or menu read QPS that saturates the primary. The split is a response to that measurement. Order and wallet in one transaction on the primary, with a unique idempotency key. Search is a derived index built from change events, allowed to be seconds behind. Rider pings go to a geo index with a heartbeat TTL, never to the orders table. Postgres can do trigram and geo while small. Split when a measurement says so.

More courses

  • Jobs, linked to lessons — Browse jobs where every requirement links to the chapter that teaches it. See how ready you are, how long the gap takes to close, and which listings look stale.
  • Match a job post to courses — Paste a job post. Each skill is matched to a track here and put in learning order, foundations first.
  • React patterns from open source — Patterns extracted from Material UI, Radix, React Aria, React Hook Form, Redux Toolkit, TanStack, and Next.js — not slides about hooks.
  • Databases in depth — How a query becomes work. Indexes, isolation, locks, and the plans that explain why a page is slow — not an ORM tour.
  • NestJS: build a real API — One ticket-booking API, built in order: a plain Node server first, then NestJS modules, validation, a real database, and the features real clients lean on.
  • Microservices — Microservice patterns one diagram at a time: how to split a monolith, how services talk, and how data stays consistent without distributed transactions.
  • Kafka — A beginner-to-senior path through event logs, reliable delivery, production operations, and disaster recovery.
  • AI engineering for software engineers — Eight free reads, in order, for software engineers moving into AI: when to build an agent, how to build one, how to test it, and how the model works underneath.
  • Frontend system design — How a UI is sliced when it is a product, not a page: ownership of state, cache, routes, and what happens when the network lies.
  • TypeScript in depth — The type system as a design tool. Inference, narrowing, generics, and the errors that mean the model is wrong — not a catalog of utility types.
  • CSS in depth — See the box, then the page. Visual chapters from the box model through Flexbox surprises, Grid, selectors, and units, then backgrounds, shapes, and visual effects, each with a playground.
  • Accessibility — Foundations first (WCAG in plain words, semantic HTML, lists, alt text), then hands-on HTML labs, a full pass of WAI-ARIA 1.3, and a final fix-the-page challenge.
  • Docker — What an image is, why layers cache, and how containers find each other on a network.
  • Redis — Fifteen Redis patterns, one picture each: cache, session, lock, counter, rate limiter, queue, and when Redis is the wrong tool.
  • Kubernetes — Kubernetes from zero to operators: why it exists, Pods, Deployments and Services, then configuration, networking, storage, scheduling, scaling and security.
  • AWS — AWS networking in plain English. A VPC is a gated housing society: streets are subnets, the Internet Gateway is the main gate, and a route table is the signboard.
  • Networking: the NetRoute game — NetRoute is a packet logistics game. You wire up computers, switches, routers, firewalls and gateways, set each device, and watch glowing packets travel. If a packet gets dropped, the game shows you which header field was wrong.