AI Hints
Home›System Design Tutorial›Gateways and Practice
System Design · Lesson 23 of 120

Practice: Design an API

A shop's endpoints.

⏱ 2 min read▶ Video at 26:06🎓 Free
Watch this lesson in the System Design courseWatch on YouTube ↗Full System Design course

Time to practise. Shoply needs an API for its mobile app. Users browse products, add them to a cart, and place orders. Pause, and sketch the endpoints yourself before I show mine.

Practice: Design an API
From the video: Practice: Design an API
  • Browse products
  • Fill a cart
  • Place an order

One possible answer

Here's one answer. Get slash v one slash products, with search and a cursor. Get one product by ID. Post to the cart to add an item. Get the cart. And post slash orders, with an idempotency key header, so a retried checkout never creates two orders.

EndpointPurpose
GET /v1/products?q=&after=search, paginated
GET /v1/products/{id}one product
POST /v1/cart/itemsadd to cart
GET /v1/cartsee the cart
POST /v1/orderscheckout (Idempotency-Key)

What we used

Notice what we used from earlier lessons. Plural nouns, and a version in the path. Cursor pagination for long lists. Proper verbs. And an idempotency key on the one call where a duplicate would really hurt, placing an order.

keyvalue
Nouns + /v1clean and versioned
Cursorfor long lists
VerbsGET reads, POST creates
Idempotency keyon checkout

Summary

A good API design combines clear resources, versions, pagination, and idempotency. Next, a quick quiz on networking and APIs.

Key takeaways
  • Resources first
  • Paginate lists
  • Protect checkout
Next up: Networking Quiz — test yourself