Alex Xu Profile picture
Sep 6 9 tweets 3 min read
/1 What does API gateway do?

The diagram below shows the detail.
/2 Step 1 - The client sends an HTTP request to the API gateway.

Step 2 - The API gateway parses and validates the attributes in the HTTP request.

Step 3 - The API gateway performs whitelist or blacklist checks.
/3 Step 4 - The API gateway talks to an identity provider for authentication and authorization.

Step 5 - The rate limiting rules are applied to the request. If it is over the limit, the request is rejected.
/4 Steps 6 and 7 - Now that the request has passed basic checks, the API gateway finds the relevant service to route to by path matching.

Step 8 - The API gateway transforms the request into the appropriate protocol and sends it to backend microservices.
/5 Steps 9-12: The API gateway can handle errors properly, and deals with faults if the error takes a longer time to recover (circuit break). It can also leverage ELK (Elastic-Logstash-Kibana) stack for logging and monitoring. We sometimes cache data in the API gateway.
/6 Over to you: 1) What’s the difference between a load balancer and an API gateway?

2) Do we need to use different API gateways for PC, mobile and browser separately?
/7 I hope you've found this thread helpful.

Follow me @alexxubyte for more.

Like/Retweet the first tweet below if you can:
Edit: update whitelist/blacklist to the modern equivalents allow-list/deny-list
Enjoy this thread?

You might like our System Design newsletter as well:

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Alex Xu

Alex Xu Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @alexxubyte

Sep 8
/1 Choosing the right database is often the most important decision we'll ever make.

We are talking about a database for a real growing business, where a bad choice would lead to extended downtime, customer impact, and even data loss.

This take is probably a bit controversial. Image
/2 The thread was written by @sahnlam and illustrated by me.
/3 𝐅𝐢𝐫𝐬𝐭, 𝐚𝐫𝐞 𝐰𝐞 𝐩𝐨𝐬𝐢𝐭𝐢𝐯𝐞 𝐭𝐡𝐚𝐭 𝐰𝐞 𝐧𝐞𝐞𝐝 𝐚 𝐝𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐭 𝐝𝐚𝐭𝐚𝐛𝐚𝐬𝐞? Is the existing database breaking at the seams? Maybe the p95 latency is through the roof. Maybe the working set is overflowing the available memory.
Read 14 tweets
Sep 7
/1 What is GraphQL? Is it a replacement for the REST API?

The diagram below shows the quick comparison between REST and GraphQL. Image
/2 🔹GraphQL is a query language for APIs developed by Meta. It provides a complete description of the data in the API and gives clients the power to ask for exactly what they need.

🔹GraphQL servers sit in between the client and the backend services.
/3 🔹GraphQL can aggregate multiple REST requests into one query. GraphQL server organizes the resources in a graph.

🔹GraphQL supports queries, mutations (applying data modifications to resources), and subscriptions (receiving notifications on schema modifications).
Read 5 tweets
Sep 1
/1 What happens behind the scenes when we 𝐬𝐡𝐨𝐩 𝐨𝐧𝐥𝐢𝐧𝐞?

Disclaimer: I have limited knowledge of the eCommerce system. The diagram below is based on my research. Please suggest better names for the components or let me know if you spot an error. Image
/2 The diagram below shows the 4 key business areas in a typical e-commerce company: procurement, inventory, eComm platform, and transportation.

1️⃣ Procurement

Step 1 - The procurement department selects suppliers and manages contracts with them. Image
/3 Step 2 - The procurement department places orders with suppliers, manages the return of goods, and settles invoices with suppliers. Image
Read 10 tweets
Aug 31
/1 What does a typical microservice architecture look like? 👇

The diagram below shows a typical microservice architecture.

🔹Load Balancer: This distributes incoming traffic across multiple backend services.
/2 🔹CDN (Content Delivery Network): CDN is a group of geographically distributed servers that hold static content for faster delivery. The clients look for content in CDN first, then progress to backend services.
/3 🔹API Gateway: This handles incoming requests and routes them to the relevant services. It talks to the identity provider and service discovery.

🔹Identity Provider: This handles authentication and authorization for users.
Read 9 tweets
Aug 30
/1 Which latency numbers we should know?

Please note those are not accurate numbers. They are based on some online benchmarks (Jeff Dean’s latency numbers + some other sources).
/2 🔹L1 and L2 caches: 1 ns, 10 ns
E.g.: They are usually built onto the microprocessor chip. Unless you work with hardware directly, you probably don’t need to worry about them.
/3 🔹RAM access: 100 ns
E.g.: It takes 100 ns to read data from memory. Redis is an in-memory store, so it takes about 100 ns to read data from Redis

🔹Send 1K bytes over 1 Gbps network: 10 us
E.g.: It takes around 10 us to send 1KB of data from Memcached through the network
Read 9 tweets
Aug 29
/1 Big accounts, such as Nike, Procter & Gamble & Nintendo, often cause hotspot issues for the payment system.

A hotspot payment account is an account that has a large number of concurrent operations on it.
/2 For example, when merchant A starts a promotion on Amazon Prime day, it receives many concurrent purchasing orders. In this case, the merchant’s account in the database becomes a hotspot account due to frequent updates.
/3 In normal operations, we put a row lock on the merchant’s balance when it gets updated. However, this locking mechanism leads to low throughput and becomes a system bottleneck.

The diagram below shows several optimizations.
Read 9 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(