Design Shopify
Understanding the Problem
🏪 What is Shopify? Shopify is a platform that lets anyone run an online store without building one. A merchant signs up, picks a theme, adds products and connects a domain, and the platform hosts the storefront, the checkout and the admin. Millions of stores share the same infrastructure, from a one-person candle shop to brands that sell out a product drop in minutes.
What makes this different from designing an e-commerce site is multi-tenancy. We're not building one store; we're building a factory for millions of them, on shared machines, where every tenant must feel like they have the platform to themselves. The questions an interviewer pushes on are about isolation, customization and routing, more than about any single store's catalog.
Functional Requirements
Core Requirements
- Merchants should be able to create a store, add products and customize its look with a theme.
- Shoppers should be able to browse a store and check out.
- Merchants should be able to serve their store on their own domain (
www.candleshop.com), with HTTPS. - Merchants (and apps they install) should be able to add custom fields to their data and define custom objects, like a "care instructions" field on products or a "Warranty" object linked to orders.
Below the line (out of scope)
- The app marketplace, billing merchants for the platform and payouts.
- Point-of-sale hardware, shipping labels and fulfillment networks.
- Recommendations and marketing tools.
Non-Functional Requirements
Ask your interviewer how big the platform is and how unequal the tenants are. We'll assume 5M active stores. Most are tiny: the majority get a few orders a day. A few thousand large merchants generate a big share of the traffic, and some run product drops that bring hundreds of thousands of shoppers to one store at a set time.
Core Requirements
- Tenants must be isolated. A shopper or merchant must never see another store's data, and one store's traffic spike must not slow down the others.
- Storefront pages should load fast everywhere: time to first byte under ~200 ms for cached pages, under ~500 ms for uncached ones.
- The platform should handle 1M storefront requests per second and 10k checkouts per second at a peak shopping event like Black Friday.
- Checkout should be highly available (99.99%). It's the one page where downtime directly costs every merchant money.
- A merchant who connects a custom domain should have it live with a valid certificate within a few minutes.
Below the line (out of scope)
- Data residency per country (it fits into the pod model below, but we won't design it).
- Detailed PCI scope. Card data is tokenized by a payment vault and never touches the store's database.
The back-of-the-envelope:
- Catalog. 5M stores × ~500 products on average = 2.5B products. At ~5 KB each, about 12 TB, and the largest stores have millions of products each.
- Orders. A couple of billion orders a year at ~5 KB each is on the order of 10 TB a year, kept for years.
- Storefront. 1M requests per second at peak. If the edge cache serves 80 to 90% of page views, ~100k to 200k per second reach our render tier.
- Checkout. 10k checkouts per second, each a handful of writes (order, line items, inventory, payment record), so ~50k writes per second across the platform.
No single database holds tens of terabytes of hot, growing data and 50k writes per second, so the data has to be split. The interesting part is that a store is a natural unit to split on. Almost every query a store makes is about itself: its products, its orders, its customers. There are very few queries that need two stores at once.
The hard part of multi-tenancy isn't adding a
shop_idcolumn. It's that tenants are wildly unequal. The median store would fit on a Raspberry Pi; the biggest one can out-traffic a hundred thousand others combined, and it may do so with ten minutes' notice. Every design decision here is about putting tenants in the right place and stopping any one of them from hurting the rest.