ฝึกพูดภาษาอังกฤษด้วยเทคนิค Shadowing จากวิดีโอ: System Design: How to Build an API Rate Limiter

กำลังสร้างบทเรียน...
1
Let's design an API rate limiter for an application that takes thousands of requests per second.
2
User journey is simple.
3
User can make API calls to your server to do something.
4
Each user is allowed to make 100 API calls per minute.
5
If a user makes more than 100 calls per minute, then your server will not process those API calls.
6
Most engineers approach this problem with a counter.
7
For each user, you store user ID, count of API calls, and current minute.
8
Every time a request is made by user, you increase this count, and you will reject the requests once it passes 100 requests.
9
This implementation is good enough for internal API calls, but let's take two specific examples why this solution is not good.
10
Let's say user Alan is a burst user, and makes 100 API calls in first two seconds.
11
Then he will get rejected for the next 58 seconds.
12
Alan will be able to make calls when next minute starts.
13
And our second user, John, sends 100 API requests, but these requests are sent at the last second of the current minute.
14
The next second clock will reset to new minute, and John can send another 100 requests.
15
Basically, John sent 200 requests in 2 seconds, because according to Counter, these 100 requests belong to different minutes.
16
Basically, users will experience different behavior of APIs based on when they make the API call.
17
There is a fundamental issue with the approach we just discussed.
18
The Counter is watching the clock instead of watching the user.
19
Let's see a better approach.
20
So, we will give every user a bucket that holds 100 tokens.
21
Every API request from user takes one token out, and we will keep filling the bucket at a rate of 100 tokens per minute, which is approximately 1.67 tokens per second.
22
For simplification, let's assume we will fill two tokens per second.
23
If user doesn't make any API call, the bucket will remain at 100, and we don't need to fill.
24
If the bucket is empty, we will reject the request.
25
This token bucket approach is what Stripe, GitHub, and most API gateways actually use for tracking API calls.
26
Now let's take a look at Alan and John's requests again, and see how this bucket system will work.
27
Alan drains all 100 tokens in 2 seconds.
28
Then Alan has to slow down.
29
Bucket fills about 2 tokens per second.
30
That's why he can now make 2 calls per second.
31
John, who is making 100 API calls at the end of the minute, will also need to wait for Bucket to fill, because once he makes 100 requests in a second, Bucket will get empty.
32
So he can also make about 2 per second, as Bucket fills with time.
33
Next question is, how do we store these buckets?
34
We just need to store the token count, and the time of the last refill, so that you can add tokens per second.
35
But what if your app works at large scale, and you have 20 different servers accepting API calls.
36
Two requests for the same user can land on two servers in the same millisecond.
37
Therefore, you keep the bucket outside the servers, in one common shared storage.
38
This storage needs to be fast, and that's why we usually use Redis.
39
When any of these 20 servers processes any API call, we change the count at this common Redis.
40
To make this crystal clear in your mind, you need to remember that request limit is not just one number.
41
It's two numbers.
42
First, how much a user can burst in one go, and second, how fast they can go after the burst.

Vocabulary and speaking notes for this lesson

This C1 speaking lesson is built on the video “System Design: How to Build an API Rate Limiter”. The speaker keeps coming back to these words: Api, user, request, bucket, token. This video has 42 sentences and 594 words to shadow. The speech runs for 2:47. The speaker talks fast, about 213 words per minute, so expect linked and reduced sounds. 82% of the words are among the 3,000 most common in English; the rest is worth studying before you start.

Key vocabulary in this video

The 15 most advanced words in the video, with pronunciation and meaning:

WordPronunciationMeaning
bucket noun/ˈbʌkɪt/A container made of rigid material, often with a handle, used to carry liquids or small items.
token noun/ˈtoʊkən/Something serving as an expression of something else.
server noun/ˈsɝvɚ/A program that provides services to other programs or devices, either in the same computer or over a computer network.
burst verb/bɜːst/To break from internal pressure.
clock noun/klɑk/A chronometer, an instrument that measures time, particularly the time of day.
crystal noun/ˈkɹɪstəl/A solid composed of an array of atoms or molecules possessing long-range order and arranged in a pattern which is periodic in three dimensions.
belong verb/bɪˈlɒŋ/To have its proper place.
fundamental adjective/ˌfʌn.dəˈmɛn.təl/Related to a foundation, base, or basis; serving as a foundation.
implementation noun/ˌɪmplɪmənˈteɪʃən/The process of moving an idea from concept to reality. In business, engineering and other fields, implementation refers to the building process rather than the…
drain noun/dɹiːn/A conduit allowing liquid to flow out of an otherwise contained volume; a plughole (UK)
gateway noun/ˈɡeɪtˌweɪ/A passage that can be closed by use of a gate.
reset verb/ɹiːˈsɛt/To set back to the initial state.
limiter nounThat which limits or confines.
millisecond noun/ˈmɪlɪˌsɛkənd/An SI unit of time equal to 10⁻³ seconds. Symbol: ms
refill noun/ˈɹiː.fɪl/An additional helping of food or drink at reduced cost.

Phrasal verbs you will hear

WordMeaning
slow down verbTo decelerate.

ไวยากรณ์ในวิดีโอนี้

โครงสร้างที่ผู้พูดใช้บ่อยที่สุด พร้อมคำพูดจริงจากวิดีโอ:

โครงสร้างในวิดีโอ
ประโยคเงื่อนไข if + อนุประโยค, will/would + กริยา — เงื่อนไขและผลลัพธ์If the bucket is empty, we will reject
Passive voice be + กริยาช่อง 3 — เน้นสิ่งที่เกิดขึ้น ไม่ใช่ผู้กระทำis allowed · is made · are sent

Pronunciation to watch

  • The “sh” and “zh” sounds: implementation /ˌɪmplɪmənˈteɪʃən/, simplification /ˌsɪm.plɪ.fɪˈkeɪ.ʃən/
  • Long words — get the stress right: fundamental /ˌfʌn.dəˈmɛn.təl/, implementation /ˌɪmplɪmənˈteɪʃən/, millisecond /ˈmɪlɪˌsɛkənd/, simplification /ˌsɪm.plɪ.fɪˈkeɪ.ʃən/

How to practise with this video

  1. Listen to the whole video once without speaking and note the words you do not know.
  2. Start at 0.75× speed, shadow it sentence by sentence, then go back to normal speed once it feels easy.
  3. Record yourself and compare with the original, paying attention to words like bucket, token, server.

เทคนิค Shadowing คืออะไร?

Shadowing เป็นเทคนิคการเรียนรู้ภาษาที่ได้รับการรับรองทางวิทยาศาสตร์ พัฒนาขึ้นสำหรับการฝึกนักแปลมืออาชีพ วิธีการนี้เรียบง่ายแต่ทรงพลัง: คุณฟังเสียงภาษาอังกฤษจากเจ้าของภาษาและพูดตามทันที — เหมือนเงาที่ตามผู้พูดด้วยช่วงเวลาห่าง 1-2 วินาที การวิจัยแสดงว่าเทคนิคนี้ปรับปรุงความแม่นยำในการออกเสียง ทำนองเสียง จังหวะ การเชื่อมเสียง การฟังเข้าใจ และความคล่องแคล่วในการพูดได้อย่างมีนัยสำคัญ

เทคนิค shadowing: อ่านคู่มือฉบับเต็มทีละขั้นตอน →