シャドーイング練習: 2.2k - YouTubeで英語スピーキングを学ぶ

C2
Hey friends, welcome back to the channel.
⏸ 一時停止中
129
文が短すぎたり長すぎる場合は、Editをタップして調整してください。
1
Hey friends, welcome back to the channel.
2
So when designing an API,
3
it's easy to think about the happy path of your application.
4
But if you want to build a robust application and keep your users happy,
5
then you need to consider the unhappy path as well.
6
What happens if your user's internet connection cuts out just after making a request?
7
Or maybe your server's struggling under load and the client times out before it can receive a response?
8
Usually errors are handled by the client by doing retries.
9
If there's an error or the request times out,
10
then the client will retry a number of times,
11
either automatically or by a frustrated user hitting that submit button.
12
If the user sends multiple requests to the server and more than one of them gets through,
13
then you'll likely end up with duplicates on your end.
14
Depending on the application, this might not be a big deal.
15
If the user is just writing a comment on a blog post or reviewing a product,
16
then it's not the end of the world if they end up with multiple posts.
17
But what if they're sending an email?
18
Is it okay for the recipients to receive multiple copies of the same email?
19
What if they were buying something online?
20
Would the customer be happy if they got charged twice or maybe even 10 times for the same product.
21
This is where idempotency comes in but what does it actually mean?
22
If we have a look at the internet standards it says the following.
23
A request method is considered idempotent
24
if the intended effect on the server of multiple identical requests with
25
that method is the same as the effect for a single such request.
26
So if we call an API multiple times with the same request then it's considered idempotent
27
if it has the same effect on the server as if we had only called it once.
28
Now let's have a look at the most common methods and see whether they're idempotent or not.
29
The get method is read only,
30
it doesn't affect the server in any way.
31
Nothing gets created or updated so we can call the get method multiple times without it having any adverse effects.
32
So a get method is always idempotent.
33
With a put request we're going to be performing updates.
34
So let's say we're updating a user's email address.
35
No matter how many times we call this method we should always get the same response
36
and the user's details are always going to get updated to the same thing.
37
So a put request is always idempotent as well.
38
With a post request we're creating something on the server.
39
So if we call this method multiple times then we should expect to get multiple copies of the same thing.
40
Or in some cases we might get an error if we're trying to create something that can only be one of.
41
For example if we're trying to create a new user with a post request.
42
Then the first request will go through but a second request for the same username will fail because the user already exists.
43
Technically this is still idempotent but it's not a very nice experience for the user user.
44
Let's say when they make their first request they then have an internet connection failure and therefore don't get a response.
45
When they try and retry it will tell them
46
that the username order exists but in fact it was their first request that created that user.
47
If we take the example of making a payment then generally
48
there aren't any unique identifiers on a payment like there are with creating a user.
49
This is what we typically might send through on a platform like Stripe if someone's buying something for $20.
50
However there is nothing unique about this request that links it to a particular purchase.
51
If a payment platform receives two of these then it'll just think it's two separate payments and charge the customer twice
52
which is not what we want.
53
So post requests are generally not idempotent.
54
With patch requests it depends on how you use them.
55
If you're just using it to update an email address of a user then that could be considered idempotent.
56
However you can also use a patch request to do things like copy,
57
move, add and remove and therefore it's not considered idempotent.
58
Finally we have the delete method which deletes an object on the server.
59
If you run delete multiple times it's going to have the same effect on the server as
60
if you'd only run it once.
61
Sure the second time you might run it you might get an error
62
but the actual server doesn't change its state therefore delete is also considered to be idempotent.
63
In the cases where you're making a payment or some other Crisco operation
64
that needs to happen exactly once then you need to make those other methods such as post and patch idempotent as well.
65
The only way that you can really do this is to have some form of unique identifier.
66
That way you can distinguish that request from some otherwise identical requests.
67
You may have something like this already in place.
68
Let's go back to the payment analogy.
69
Let's say you have a saved basket of items and that basket has an ID.
70
That ID is therefore unique to that order and you could use that ID for the idempotency key.
71
Another option is to hash the body of the request.
72
However if you're doing this you need to make sure
73
that there's no reason for that person to ever send exactly the same request.
74
There should be something about the combination of fields in the request that makes it unique.
75
For example if someone orders a Spongebob beach towel
76
and then 30 seconds later orders another Spongebob beach towel you don't know that that's a duplicate order.
77
They might just really like Spongebob.
78
Generally the way this is normally done is to add an idempotency key to a header.
79
Stripe for example have a header called idempotency-key but really this could be anything.
80
So you now have some form of key that makes this request unique.
81
However with a user supplied key you can't guarantee that it's going to be globally unique.
82
The user could send you the same key as another user or even the same key from multiple endpoints.
83
So it's important you always combine
84
that user supply key with something like a user id as well as the API path that's being used.
85
To implement idempotency you need to store your combined idempotency key along with the successful response that you send to the user.
86
If a request with the same idempotency key comes in instead of actually performing the operation,
87
you just send them back a response that you sent out before.
88
As far as the user is concerned,
89
the operation was successful and they don't need to know that you're sending out a previous response.
90
Typically this is done using some form of key value storage such as Redis or DynamoDB.
91
Technically you could store your idempotency keys in an in-memory storage such as a dictionary.
92
However this won't work if you have multiple copies of your API running behind the load balancer,
93
as each API won't be able to see the keys in the other copies.
94
You will also lose your idempotency keys whenever you have to restart your application.
95
This is why we don't store them in memory.
96
So when a request comes in you need to first check to see whether
97
that idempotency key that's been sent is in your storage.
98
And if it is then you just send back the response that you have stored.
99
If the idempotency key doesn't exist then you carry on with the normal operation
100
and if it's successful then you store the idempotency key along with the response before sending it back to the user.
101
How long you store your idempotency keys for really depends on the application.
102
If you have idempotency enabled just to protect yourself from a
103
user clicking on something multiple times then you might only need to store them for say 10 minutes.
104
But if you have some sort of retry mechanism in place then you might need to store them for longer.
105
Typically we store idempotency keys for anywhere between 24 and 48 hours
106
but you need to check with your application and see if it makes sense to store them for longer.
107
If you are using something like redis
108
or dynamo db to store your keys then you can use the time to live
109
or ttl so that your keys are automatically deleted for you.
110
You may also want to consider idempotency validation in your API.
111
If a request comes in with the same idempotency key from
112
the same user for the same endpoint then we're just going to assume
113
that that's the same request and send them out the same response.
114
However there is a chance
115
that the user has just used the same idempotency key by mistake and the request body is actually very different.
116
If you need to protect yourself against this sort of scenario then you can take a hash of the request
117
and store that alongside the idempotency key and then
118
when the request comes in you can check to see whether it matches the hash as well
119
and if it doesn't return an error to the user.
120
If you want to implement this in the .NET Core API then you can make use of the distributed caching library
121
and then store your keys in redis and then you can create a filter
122
which you can then add to each of the endpoints where
123
you want idempotency to make this even easier there is a new get package called idempotent api
124
that does all the heavy lifting for you
125
if you want to support this channel
126
and also get access to the code shown in my videos
127
and you can subscribe on patreon patreon members also get access
128
to exclusive content from me as well as a private discord community and generous discounts to my courses once I release them.
129
Thank you for watching this video and I'll hopefully see you in the next one.

アプリをダウンロード

話したすべての文をAIが採点

スキャンしてダウンロード
スキャンしてダウンロード
TRENDING

人気動画

このレッスンについて

このレッスンでは、API設計における重要なコンセプトである「アイデポンデンシー」(idempotency)について学びます。具体例を通じて、同じリクエストを何度行ってもサーバーに与える影響が変わらないことがどのように業務に影響を与えるのかを理解し、また、APIを利用するシナリオでのユーザー体験を考慮することが重要である点を強調します。この知識は、英語のリスニングスキルを向上させるだけでなく、実際の会話やビジネスコミュニケーションにも役立つでしょう。

重要な語彙とフレーズ

  • アイデポンデンシー - 同じリクエストが何度行われても、サーバーに与える影響が変わらない特性。
  • リクエスト - サーバーへ送られる要求。
  • サーバー - データを管理し、リクエストに応答するコンピュータ。
  • タイムアウト - リクエストに対する応答が得られなかったときに発生する状況。
  • PUTリクエスト - データを更新するためのリクエスト。
  • POSTリクエスト - 新しいデータをサーバーに作成するためのリクエスト。
  • ユーザー体験 - ユーザーがサービスを利用したときの感覚や反応。
  • 重複 - 同じリクエストが複数回行われた場合に発生する問題。

練習のコツ

このビデオの内容を効果的に学ぶためには、shadowspeakの技術を活用することをお勧めします。ビデオのスピードやトーンに合わせて声を出し、講師の言葉を耳で聞き取りながら模倣してください。特に、重要な語彙やフレーズを繰り返すことで、自然なイントネーションやリズムを身につけることができます。また、YouTubeで英語学習をしながら練習する際には、特定のフレーズを一時停止し、ゆっくり自分の声で言ってみると良いでしょう。これにより、shadow speakの実践を通じて、スピーキングスキルが向上し、IELTSスピーキング対策にも役立ちます。効果的な練習を行うことで、今後の発表やコミュニケーションに自信を持つことができるようになるでしょう。

シャドーイングとは?英語上達に効果的な理由

シャドーイング(Shadowing)は、もともとプロの通訳者養成プログラムで開発された言語学習法で、多言語習得者として知られるDr. Alexander Arguelles によって広く普及されました。方法はシンプルですが非常に効果的:ネイティブスピーカーの英語を聞きながら、1〜2秒の遅延で声に出してすぐに繰り返す——まるで「影(shadow)」のように話者を追いかけます。文法ドリルや受動的なリスニングと異なり、シャドーイングは脳と口の筋肉が同時にリアルタイムで英語を処理・再現することを強制します。研究により、発音精度、抑揚、リズム、連音、リスニング力、そして会話の流暢さが大幅に向上することが確認されています。IELTSスピーキング対策や自然な英語コミュニケーションを目指す方に特におすすめです。

コーヒーをおごる