### Object Download Request Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/24. S3-like Object Storage/README.md
Demonstrates an HTTP GET request for downloading an object from an S3-like storage. Specifies the host, date, and authorization headers.
```http
GET /bucket-to-share/script.txt HTTP/1.1
Host: foo.s3example.org
Date: Sun, 12 Sept 2021 18:30:01 GMT
Authorization: authorization string
```
--------------------------------
### Navigation Service Request Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/18. Google Maps/README.md
Example of a GET request to the navigation service to find a route between two locations. Origin and destination can be specified as addresses or coordinates.
```http
GET /v1/nav?origin=1355+market+street,SF&destination=Disneyland
```
--------------------------------
### Navigation Service Response Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/18. Google Maps/README.md
Example JSON response from the navigation service, detailing route information such as distance, duration, and instructions.
```json
{
"distance": {"text":"0.2 mi", "value": 259},
"duration": {"text": "1 min", "value": 83},
"end_location": {"lat": 37.4038943, "Ing": -121.9410454},
"html_instructions": "Head northeast on Brandon St toward Lumin Way
Restricted usage road
",
"polyline": {"points": "_fhcFjbhgVuAwDsCal"},
"start_location": {"lat": 37.4027165, "lng": -121.9435809},
"geocoded_waypoints": [
{
"geocoder_status" : "OK",
"partial_match" : true,
"place_id" : "ChIJwZNMti1fawwRO2aVVVX2yKg",
"types" : [ "locality", "political" ]
},
{
"geocoder_status" : "OK",
"partial_match" : true,
"place_id" : "ChIJ3aPgQGtXawwRLYeiBMUi7bM",
"types" : [ "locality", "political" ]
}
],
"travel_mode": "DRIVING"
}
```
--------------------------------
### Adaptive ETA Data Storage Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/18. Google Maps/README.md
Example data structure for storing user navigation paths using routing tiles for adaptive ETA and rerouting. This format helps in efficiently identifying users affected by traffic incidents.
```Plain Text
user_1: r_1, r_2, r_3, …, r_k
user_2: r_4, r_6, r_9, …, r_n
user_3: r_2, r_8, r_9, …, r_m
...
user_n: r_2, r_10, r21, ..., r_l
```
--------------------------------
### Example Response for Specific User Score
Source: https://github.com/liquidslr/system-design-notes/blob/main/25. Real-time Gaming Leaderboard/README.md
This is an example JSON response when fetching the score and rank for a particular user.
```json
{
"user_info": {
"user_id": "user5",
"score": 1000,
"rank": 6,
}
}
```
--------------------------------
### Example Response for Top 10 Scores
Source: https://github.com/liquidslr/system-design-notes/blob/main/25. Real-time Gaming Leaderboard/README.md
This is an example JSON response when fetching the top 10 players from the leaderboard.
```json
{
"data": [
{
"user_id": "user_id1",
"user_name": "alice",
"rank": 1,
"score": 12543
},
{
"user_id": "user_id2",
"user_name": "bob",
"rank": 2,
"score": 11500
}
],
...
"total": 10
}
```
--------------------------------
### Time-Series Data Example (Line Protocol)
Source: https://github.com/liquidslr/system-design-notes/blob/main/20. Metrics Monitoring and Alerting System/README.md
This is an example of time-series data in line protocol format, commonly used by monitoring software like Prometheus and OpenTSDB. It includes metric name, labels, timestamp, and value.
```text
CPU.load host=webserver01,region=us-west 1613707265 50
CPU.load host=webserver01,region=us-west 1613707265 62
CPU.load host=webserver02,region=us-west 1613707265 43
CPU.load host=webserver02,region=us-west 1613707265 53
...
CPU.load host=webserver01,region=us-west 1613707265 76
CPU.load host=webserver01,region=us-west 1613707265 83
```
--------------------------------
### Geocoding API Response Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/18. Google Maps/README.md
Example JSON response from the Google Geocoding API, showing formatted address and location details.
```JSON
{
"results" : [
{
"formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
"geometry" : {
"location" : {
"lat" : 37.4224764,
"lng" : -122.0842499
},
"location_type" : "ROOFTOP",
"viewport" : {
"northeast" : {
"lat" : 37.4238253802915,
"lng" : -122.0829009197085
},
"southwest" : {
"lat" : 37.4211274197085,
"lng" : -122.0855988802915
}
}
},
"place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
"plus_code": {
"compound_code": "CWC8+W5 Mountain View, California, United States",
"global_code": "849VCWC8+W5"
},
"types" : [ "street_address" ]
}
],
"status" : "OK"
}
```
--------------------------------
### Example Folder Response
Source: https://github.com/liquidslr/system-design-notes/blob/main/23. Distributed Email Service/README.md
Illustrates the structure of a response when retrieving a list of email folders. Includes folder identifier, name, and owner reference.
```json
[
{
"id": "string",
"name": "string",
"user_id": "string"
}
]
```
--------------------------------
### Geocoding API Request Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/18. Google Maps/README.md
Example of a request to the Google Geocoding API to convert an address to latitude and longitude coordinates.
```HTTP
https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
```
--------------------------------
### Object Upload Request Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/24. S3-like Object Storage/README.md
Illustrates an HTTP PUT request for uploading an object to an S3-like storage. Includes headers for host, date, authorization, content type, length, and metadata.
```http
PUT /bucket-to-share/script.txt HTTP/1.1
Host: foo.s3example.org
Date: Sun, 12 Sept 2021 17:51:00 GMT
Authorization: authorization string
Content-Type: text/plain
Content-Length: 4567
x-amz-meta-author: Alex
[4567 bytes of object data]
```
--------------------------------
### Example Message Response
Source: https://github.com/liquidslr/system-design-notes/blob/main/23. Distributed Email Service/README.md
Shows the format of a response for a single email message. Details sender, recipients, subject, body, and read status.
```json
{
"user_id": "string",
"from": {"name": "string", "email": "string"},
"to": [{"name": "string", "email": "string"}],
"subject": "string",
"body": "string",
"is_read": "boolean"
}
```
--------------------------------
### In-Memory Sharding Algorithm
Source: https://github.com/liquidslr/system-design-notes/blob/main/27. Digital Wallet/README.md
An example algorithm for partitioning user accounts across multiple Redis nodes based on account ID hash. This is crucial for scaling beyond a single node's capacity.
```java
String accountID = "A";
Int partitionNumber = 7;
Int myPartition = accountID.hashCode() % partitionNumber;
```
--------------------------------
### Calculate User Percentile with Cron Job
Source: https://github.com/liquidslr/system-design-notes/blob/main/25. Real-time Gaming Leaderboard/README.md
This example illustrates how a cron job can periodically analyze score distributions to determine a user's percentile rank. This is useful when direct rank calculation is difficult.
```shell
10th percentile = score < 100
20th percentile = score < 500
...
90th percentile = score < 6500
```
--------------------------------
### Raw Ad Click Event Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/21. Ad Click Event Aggregation/README.md
Represents a single ad click event with details like ad ID, timestamp, user, IP, and country.
```text
[AdClickEvent] ad001, 2021-01-01 00:00:01, user 1, 207.148.22.22, USA
```
--------------------------------
### Optimized Adaptive ETA Data Storage Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/18. Google Maps/README.md
An optimized data storage approach for adaptive ETA, storing only the origin tile and progressively coarser resolution tiles until the destination is covered. This reduces storage requirements.
```Plain Text
user_1, r_1, super(r_1), super(super(r_1)), ...
```
--------------------------------
### List objects in a bucket with prefix (SQL)
Source: https://github.com/liquidslr/system-design-notes/blob/main/24. S3-like Object Storage/README.md
SQL query to list objects within a specific bucket that match a given prefix. This is a common operation in object storage systems.
```sql
SELECT * FROM object WHERE bucket_id = "123" AND object_name LIKE `abc/%`
```
--------------------------------
### FIX Protocol Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/28. Stock Exchange/README.md
This is an example of a FIX protocol message for a securities transaction. It includes various fields like message type, sender/target IDs, timestamps, and order details.
```plaintext
8=FIX.4.2 | 9=176 | 35=8 | 49=PHLX | 56=PERS | 52=20071123-05:30:00.000 | 11=ATOMNOCCC9990900 | 20=3 | 150=E | 39=E | 55=MSFT | 167=CS | 54=1 | 38=15 | 40=2 | 44=15 | 58=PHLX EQUITY TESTING | 59=0 | 47=C | 32=0 | 31=0 | 151=15 | 14=0 | 6=0 | 10=128 |
```
--------------------------------
### Get file revisions
Source: https://github.com/liquidslr/system-design-notes/blob/main/15. Google Drive/Readme.md
Retrieves the revision history for a specific file.
```APIDOC
## GET /files/list_revisions
### Description
Retrieves a list of revisions for a given file.
### Method
GET
### Endpoint
https://api.example.com/files/list_revisions
### Parameters
#### Query Parameters
- **file_id** (string) - Required - The unique identifier of the file whose revisions are to be listed.
### Request Example
```json
{
"example": "Request to list revisions for a file"
}
```
### Response
#### Success Response (200)
- **revisions** (array) - A list of file revisions, each containing details like version, timestamp, and author.
#### Response Example
```json
{
"revisions": [
{
"version": "1.2",
"timestamp": "2023-10-27T10:00:00Z",
"author": "user@example.com"
},
{
"version": "1.1",
"timestamp": "2023-10-26T15:30:00Z",
"author": "user@example.com"
}
]
}
```
```
--------------------------------
### Get Message Details
Source: https://github.com/liquidslr/system-design-notes/blob/main/23. Distributed Email Service/README.md
Retrieves all information about a specific email message.
```APIDOC
## GET /v1/messages/{:message_id}
### Description
Get all information about a particular message.
### Method
GET
### Endpoint
/v1/messages/{:message_id}
### Parameters
#### Path Parameters
- **message_id** (string) - Required - The ID of the message to retrieve.
### Response
#### Success Response (200)
- **user_id** (string) - Reference to the account owner.
- **from** (object) - Sender information.
- **name** (string) - Sender's name.
- **email** (string) - Sender's email address.
- **to** (array) - List of recipients.
- **name** (string) - Recipient's name.
- **email** (string) - Recipient's email address.
- **subject** (string) - Subject of the email.
- **body** (string) - Body of the email.
- **is_read** (boolean) - Indicates if the message has been read.
```
--------------------------------
### Get Specific User's Rank
Source: https://github.com/liquidslr/system-design-notes/blob/main/25. Real-time Gaming Leaderboard/README.md
Retrieves the score and rank for a specific user.
```APIDOC
## GET /v1/scores/{:user_id}
### Description
Fetches the score and rank for a specific user identified by their user ID.
### Method
GET
### Endpoint
/v1/scores/{:user_id}
### Parameters
#### Path Parameters
- **user_id** (string) - Required - The unique identifier of the user whose information is being requested.
### Response
#### Success Response (200)
- **user_info** (object) - An object containing the user's details.
- **user_id** (string) - The user's unique identifier.
- **score** (integer) - The user's current score.
- **rank** (integer) - The user's current rank on the leaderboard.
### Response Example
{
"user_info": {
"user_id": "user5",
"score": 1000,
"rank": 6
}
}
```
--------------------------------
### Hotel Reservation API Request Example
Source: https://github.com/liquidslr/system-design-notes/blob/main/22. Hotel Reservation System/README.md
This JSON object represents a sample request payload for making a hotel reservation. It includes dates, hotel and room identifiers, and an idempotency key to prevent double bookings.
```json
{
"startDate":"2021-04-28",
"endDate":"2021-04-30",
"hotelID":"245",
"roomID":"U12354673389",
"reservationID":"13422445"
}
```
--------------------------------
### Get Top 10 Players
Source: https://github.com/liquidslr/system-design-notes/blob/main/25. Real-time Gaming Leaderboard/README.md
Retrieves the top 10 players from the leaderboard, including their rank and score.
```APIDOC
## GET /v1/scores
### Description
Fetches the top 10 players currently on the leaderboard.
### Method
GET
### Endpoint
/v1/scores
### Response
#### Success Response (200)
- **data** (array) - An array of player objects, each containing user_id, user_name, rank, and score.
- **total** (integer) - The total number of players returned in the data array (expected to be 10 for this endpoint).
### Response Example
{
"data": [
{
"user_id": "user_id1",
"user_name": "alice",
"rank": 1,
"score": 12543
},
{
"user_id": "user_id2",
"user_name": "bob",
"rank": 2,
"score": 11500
}
],
"total": 10
}
```
--------------------------------
### Get Payment Status
Source: https://github.com/liquidslr/system-design-notes/blob/main/26. Payment System/README.md
Retrieves the execution status of a single payment order using its unique identifier.
```APIDOC
## GET /v1/payments/{:id}
### Description
Retrieves the execution status of a single payment order based on the provided payment order ID.
### Method
GET
### Endpoint
/v1/payments/{:id}
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the payment order (`payment_order_id`) to query.
```
--------------------------------
### Get Candlesticks
Source: https://github.com/liquidslr/system-design-notes/blob/main/28. Stock Exchange/README.md
Retrieves historical candlestick data for a given stock symbol over a specified time range and resolution.
```APIDOC
## Get Candlesticks
### Description
Retrieves historical candlestick data for a given stock symbol over a specified time range and resolution.
### Method
GET
### Endpoint
/marketdata/candles
### Parameters
#### Query Parameters
- **symbol** (String) - Required - The stock symbol.
- **resolution** (Long) - Required - Window length of the candlestick chart in seconds.
- **startTime** (Long) - Required - Start time of the window in epoch.
- **endTime** (Long) - Required - End time of the window in epoch.
### Response
#### Success Response (200)
- **candles** (Array) - Array with each candlestick data.
- **open** (Double) - Open price of each candlestick.
- **close** (Double) - Close price of each candlestick.
- **high** (Double) - High price of each candlestick.
- **low** (Double) - Low price of each candlestick.
```
--------------------------------
### Payment Service API - Get Payment Status
Source: https://github.com/liquidslr/system-design-notes/blob/main/26. Payment System/README.md
This endpoint retrieves the execution status of a single payment using the `payment_order_id`.
```http
GET /v1/payments/{:id}
```
--------------------------------
### Order Book Data Structures (Pseudo Code)
Source: https://github.com/liquidslr/system-design-notes/blob/main/28. Stock Exchange/README.md
Defines the core classes for an order book implementation, including PriceLevel, Book, and OrderBook. These structures are foundational for managing buy and sell orders.
```pseudo
class PriceLevel{
private Price limitPrice;
private long totalVolume;
private List orders;
}
class Book {
private Side side;
private Map limitMap;
}
class OrderBook {
private Book buyBook;
private Book sellBook;
private PriceLevel bestBid;
private PriceLevel bestOffer;
private Map orderMap;
}
```
--------------------------------
### API Endpoint for Specific User Score
Source: https://github.com/liquidslr/system-design-notes/blob/main/25. Real-time Gaming Leaderboard/README.md
Use this GET endpoint to retrieve the score and rank for a specific user by their ID.
```http
GET /v1/scores/{:user_id}
```
--------------------------------
### Get Execution API Endpoint
Source: https://github.com/liquidslr/system-design-notes/blob/main/28. Stock Exchange/README.md
Retrieve details of order executions within a specified time range. The orderId parameter is optional.
```http
GET /execution?symbol={:symbol}&orderId={:orderId}&startTime={:startTime}&endTime={:endTime}
```
--------------------------------
### Insert New User into Leaderboard
Source: https://github.com/liquidslr/system-design-notes/blob/main/25. Real-time Gaming Leaderboard/README.md
Use this SQL statement to insert a new user into the leaderboard table if they do not already exist. This is typically the first interaction when a user scores.
```sql
INSERT INTO leaderboard (user_id, score) VALUES ('mary1934', 1);
```
--------------------------------
### Order Matching Algorithm Pseudocode
Source: https://github.com/liquidslr/system-design-notes/blob/main/28. Stock Exchange/README.md
This pseudocode details the process of handling new and canceled orders within an order book, including validation, order creation, and matching logic. It uses a FIFO approach for matching orders at the same price level.
```pseudocode
Context handleOrder(OrderBook orderBook, OrderEvent orderEvent) {
if (orderEvent.getSequenceId() != nextSequence) {
return Error(OUT_OF_ORDER, nextSequence);
}
if (!validateOrder(symbol, price, quantity)) {
return ERROR(INVALID_ORDER, orderEvent);
}
Order order = createOrderFromEvent(orderEvent);
switch (msgType):
case NEW:
return handleNew(orderBook, order);
case CANCEL:
return handleCancel(orderBook, order);
default:
return ERROR(INVALID_MSG_TYPE, msgType);
}
Context handleNew(OrderBook orderBook, Order order) {
if (BUY.equals(order.side)) {
return match(orderBook.sellBook, order);
} else {
return match(orderBook.buyBook, order);
}
}
Context handleCancel(OrderBook orderBook, Order order) {
if (!orderBook.orderMap.contains(order.orderId)) {
return ERROR(CANNOT_CANCEL_ALREADY_MATCHED, order);
}
removeOrder(order);
setOrderStatus(order, CANCELED);
return SUCCESS(CANCEL_SUCCESS, order);
}
Context match(OrderBook book, Order order) {
Quantity leavesQuantity = order.quantity - order.matchedQuantity;
Iterator limitIter = book.limitMap.get(order.price).orders;
while (limitIter.hasNext() && leavesQuantity > 0) {
Quantity matched = min(limitIter.next.quantity, order.quantity);
order.matchedQuantity += matched;
leavesQuantity = order.quantity - order.matchedQuantity;
remove(limitIter.next);
generateMatchedFill();
}
return SUCCESS(MATCH_SUCCESS, order);
}
```
--------------------------------
### Initiate Payment
Source: https://github.com/liquidslr/system-design-notes/blob/main/26. Payment System/README.md
Initiates a payment transaction. This endpoint accepts payment details and orchestrates the payment process through various services.
```APIDOC
## POST /v1/payments
### Description
Initiates a payment transaction. This endpoint accepts payment details and orchestrates the payment process through various services.
### Method
POST
### Endpoint
/v1/payments
### Request Body
- **buyer_info** (object) - Required - Information about the buyer.
- **checkout_id** (string) - Required - Identifier for the checkout session.
- **credit_card_info** (object) - Required - Details of the credit card used for payment.
- **payment_orders** (array) - Required - A list of payment orders associated with this transaction.
- **seller_account** (string) - Required - The seller's account identifier (e.g., IBAN).
- **amount** (string) - Required - The monetary amount for the payment order. Represented as a string to avoid floating-point inaccuracies.
- **currency** (string) - Required - The currency of the payment (e.g., USD).
- **payment_order_id** (string) - Required - A unique identifier for the payment order, used for idempotency and deduplication with the PSP.
### Request Example
```json
{
"buyer_info": {...},
"checkout_id": "some_id",
"credit_card_info": {...},
"payment_orders": [
{
"seller_account": "SELLER_IBAN",
"amount": "3.15",
"currency": "USD",
"payment_order_id": "globally_unique_payment_id"
},
{...}
]
}
```
```