System Design Flashcards
How would you design an API based order processing system using microservices?
Order details include the customer’s email, phone number and address, and an array of objects containing each product id with the quantity purchased
API has a high volume of requests
Order must be posted to a 3rd party fulfillment service and include additional product details such as the product SKU, category, and quantity as well as the customer’s address
Confirmation email and sms must be delivered to customer
You have a user base of 10,000 monthly active users. They all have one or more banks and want their financial data imported within one day into your system. Your system should categorize the transactions, allow for setting budgets, and give insights into trends.
Design a company review page where users can write reviews for various companies. 50 million companies and 100 reviews per page. A large company might have 30k reviews. Sort by date. Show average star rating out of 5.
Design Instagram with 10 users and then with 1 billion users.
Database design for a library (multiple media types, not just books..)
When designing a web-based API, describe the challenges encountered when the service scales up from low user counts during development through millions of users in production. How would you solve those challenges?
Situation One:
Assume you have two endpoints, /username
and /password
. The /username
endpoint only accepts a username, validates the username (it exists), and this has to happen before the /password
endpoint is processed. The /password
endpoint only accepts a password and is only processed for valid usernames.
How would you go about implementing this? (Think high-level, language-agnostic approach + entity relationships).
Situation Two:
Now that these two endpoints are implemented, they have to serve lots of traffic, potentially thousands of requests per second. How would you go about ensuring these services are scalable?
Design a bird watching widget into an app (an app that lets anyone view information on when/where they can go for bird watching and anyone can submit information about bird watching locations). This was focused around database schema, api design and overall system design (the different tiers involved). This widget needed to handle 100,000 unique visitors per day.
Design a SQL database to store NBA players, teams and games (column and table contents are all up to you). Users mostly query game results by date and team name. The second most frequent query is players statistics by player name.
You’re hired to create an app that figures out which websites are down or up at any given time. This app will then alert the owners of the site when it goes down.
- We want the owners to be alerted ASAP
- We outsource the alerting to another app, so don’t have to worry about that
- How would you design this system?
Explain why you chose each piece of architecture, what does it do, etc.
Design a restaurant management system. Here are some things to consider:
The restaurant will have different branches.
Each restaurant branch will have a menu.
The menu will have different menu sections, containing different menu items.
The waiter should be able to create an order for a table and add meals for each seat.
Each meal can have multiple meal items. Each meal item corresponds to a menu item.
The system should be able to retrieve information about tables currently available to seat walk-in customers.
The system should support the reservation of tables.
The receptionist should be able to search for available tables by date/time and reserve a table.
The system should allow customers to cancel their reservation.
The system should be able to send notifications whenever the reservation time is approaching.
The customers should be able to pay their bills through credit card, check or cash.
Each restaurant branch can have multiple seating arrangements of tables.
Design a parking lot. Here are some things to consider:
The parking lot should have multiple floors where customers can park their cars.
The parking lot should have multiple entry and exit points.
Customers can collect a parking ticket from the entry points and can pay the parking fee at the exit points on their way out.
Customers can pay the tickets at the automated exit panel or to the parking attendant.
Customers can pay via both cash and credit cards.
Customers should also be able to pay the parking fee at the customer’s info portal on each floor. If the customer has paid at the info portal, they don’t have to pay at the exit.
The system should not allow more vehicles than the maximum capacity of the parking lot. If the parking is full, the system should be able to show a message at the entrance panel and on the parking display board on the ground floor.
Each parking floor will have many parking spots. The system should support multiple types of parking spots such as Compact, Large, Handicapped, Motorcycle, etc.
The Parking lot should have some parking spots specified for electric cars. These spots should have an electric panel through which customers can pay and charge their vehicles.
The system should support parking for different types of vehicles like car, truck, van, motorcycle, etc.
Each parking floor should have a display board showing any free parking spot for each spot type.
The system should support a per-hour parking fee model. For example, customers have to pay $4 for the first hour, $3.5 for the second and third hours, and $2.5 for all the remaining hours.
Design the API and DB layers for a marketplace, similar to the New York Stock Exchange. Assume that users placing orders are using an existing frontend application that’ll send HTTP requests to the API.
Users should be able to play buy orders and/or sell orders. An example would be a BUY order for 20 shares of APPL at $10/share.
When someone places an order, they should be matched with an existing order to make the trade happen. Using the example from above, your system should try to match that order with an existing SELL order for 20 shares of APPL at $10/share. If can also match the BUY with a SELL order with a better price (like $9.50/share) but not a worse price (like $11/share). If there are no matching orders, then the order is saved to the DB for later.
Users will also want to know where the market is before placing an order, so they’ll need to see existing unmatched orders.
Additional info
Traffic:
- peak is a couple thousand per second
- avg is in the hundreds per second
Read volume (people wanting to view open orders) is larger than write volume (people placing orders).
Follow-up questions after finishing design
What columns should be indexed? (if you’re using a relational DB)
How does your system handle two identical orders that are placed at the same when there’s only one matching order already in the system? If your system can’t handle that properly now, how would you change it so it can?
Let’s say you have a customer with 100 servers, with each server sending 10k recurring metrics with a timestamp and a value every 10 seconds. We want a system in our datacenter to store the data and to be able to retrieve it for reads.
Each metric consists of:
a timestamp
a floating point value
an identifier string that is about 85 bytes on average.
How would you approach this problem?
Follow Up Questions:
- how would you design a database to support these requirements?
- how would you build resilience into your database on both the client-side and server-side?
Assume 1 million DAU, 1 Tweet/day
Consider these entities: Tweet, Feed, User
Ignore Comments/Retweets and Search functionality
Additional requirements and follow-up questions uncovered throughout the interview discussion:
Latency: Must be near-real-time
Availability: 5 nines
Reliability: Try not to lose any data. Tweets cannot be lost in transit.
Both writes and reads can be bursty; how to account for peak load?
Write out the data schema for each entity. Assume a Tweet can have text only, photo, video, or a combination.
Polymorphic association (media types) and Self-referential FKs (e.g. User following another User) were discussed here.
Write out the join tables for Followers/Followees, and Likes.
What mechanism will you used to populate a Feed? (e.g. push, pull, fanout)
What type of cache will you use? What’s the invalidation strategy?
Walk me through the process of when a Tweet is made, i.e. API call, cache read, persist in db, fanout, etc.
Draw a UML/ERD.