/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?
/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.
/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.
/1 What is GraphQL? Is it a replacement for the REST API?
The diagram below shows the quick comparison between REST and GraphQL.
/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).
/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.
/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.
/3 Step 2 - The procurement department places orders with suppliers, manages the return of goods, and settles invoices with suppliers.
/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.
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
/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.