Safe retries in distributed systems
Part 3: The load problem
πΊπΈ
In Part 1, we saw that retrying under load can turn a partial outage into a full outage. Idempotency keys from Part 2 solve the correctness problem, but they do nothing for the load problem. Even if your retries are safe to repeat, firing them too aggressively can take down a struggling service.
Exponential backoff
The first mistake most implementations make is retrying immediately after a failure. If a service is overloaded, hitting it with retries every few milliseconds makes the situation worse. Exponential backoff means waiting longer after each failed attempt. First retry after 1 second, second after 2, third after 4, and so on, i.e. this formula:
The thundering herd
Exponential backoff alone is not enough. Imagine thousands of clients all start retrying at the same moment, for example, after a brief outage. Even with backoff, if they all follow the same schedule, they all retry at the same intervals. The downstream service receives a spike of traffic at second 1, another at second 2, another at second 4, the load is still synchronized.
Jitter
The usual solution to this problem is is jitter - adding randomness to the backoff interval. Instead of every client waiting exactly 2 seconds, each waits a random amount between 1 and 3 seconds, i.e. this formula:
VP/Distinguished Engineer at AWS, Marc Brooker, who has written extensively on this topic, showed that in addition to reducing spiky peak load - jitter significantly improves the overall time to recovery for the whole system (MTTR). If you want to go deeper, his article Exponential Backoff And Jitter on the AWS Architecture Blog is the place to start. You can also use the distributed systems event simulation builder made by Marc here: https://stability-sim.systems/ where you can visualize the failure modes related to retries.
@abdullaevdev
#distributedsystems #retries #saferetries #aws #mttr
Part 3: The load problem
πΊπΈ
In Part 1, we saw that retrying under load can turn a partial outage into a full outage. Idempotency keys from Part 2 solve the correctness problem, but they do nothing for the load problem. Even if your retries are safe to repeat, firing them too aggressively can take down a struggling service.
Exponential backoff
The first mistake most implementations make is retrying immediately after a failure. If a service is overloaded, hitting it with retries every few milliseconds makes the situation worse. Exponential backoff means waiting longer after each failed attempt. First retry after 1 second, second after 2, third after 4, and so on, i.e. this formula:
sleep=min(max_wait, base * 2 ^ attempt). This gives the downstream service time to recover instead of making it struggle further.The thundering herd
Exponential backoff alone is not enough. Imagine thousands of clients all start retrying at the same moment, for example, after a brief outage. Even with backoff, if they all follow the same schedule, they all retry at the same intervals. The downstream service receives a spike of traffic at second 1, another at second 2, another at second 4, the load is still synchronized.
Jitter
The usual solution to this problem is is jitter - adding randomness to the backoff interval. Instead of every client waiting exactly 2 seconds, each waits a random amount between 1 and 3 seconds, i.e. this formula:
sleep=random(0, min(cap, base * 2^attempt)). The retries spread out over time, the synchronized spikes disappear, and the downstream service sees a steady traffic instead of repeated spikes.VP/Distinguished Engineer at AWS, Marc Brooker, who has written extensively on this topic, showed that in addition to reducing spiky peak load - jitter significantly improves the overall time to recovery for the whole system (MTTR). If you want to go deeper, his article Exponential Backoff And Jitter on the AWS Architecture Blog is the place to start. You can also use the distributed systems event simulation builder made by Marc here: https://stability-sim.systems/ where you can visualize the failure modes related to retries.
@abdullaevdev
#distributedsystems #retries #saferetries #aws #mttr
π₯7
Taqsimlangan sistemalarda xavfsiz qayta urinishlar
3-qism: Yuklanish muammosi
πΊπΏ
1-qismda yuklanish ostida qayta urinishlar qisman nosozlikni to'liq nosozlikka aylantirishi mumkinligini ko'rdik. 2-qismdagi idempotentlik kalitlari to'g'rilik muammosini hal qiladi, lekin yuklanish muammosiga hech qanday yordam bermaydi. Qayta urinishlaringiz xavfsiz bo'lsa ham, ularni juda agressiv tarzda yuborish qiynalayotgan servisni ishdan chiqarishi mumkin.
Eksponensial kutish (Exponential backoff)
Ko'pchilik implementatsiyalar qilgan birinchi xato bu xatolikdan so'ng darhol qayta urinish. Agar servis haddan tashqari yuklama ostida bo'lsa, har bir millisekund qayta urinish vaziyatni yanada yomonlashtiradi. Eksponensial kutish har bir muvaffaqiyatsiz urinishdan keyin tobora uzoqroq kutishni anglatadi. Birinchi qayta urinish 1 soniyadan keyin, ikkinchisi 2 soniyadan keyin, uchinchisi 4 soniyadan keyin va hokazo, ya'ni quyidagi formula bo'yicha:
Momaqaldiroq podasi (Thundering herd)
Eksponensial kutishning o'zi yetarli emas. Minglab klientlar bir vaqtning o'zida qayta urinishni boshlashini tasavvur qiling, masalan, qisqa nosozlikdan keyin. Hatto kutish bilan ham, agar ularning barchasi bir xil jadvalga amal qilsa, ular bir xil intervallarda qayta urinadi. Pastki servis 1-soniyada trafik zarbasi, 2-soniyada yana bir zarba, 4-soniyada yana bir zarba oladi, yuklanish hamon sinxronlashgan holda qoladi.
Jitter
Bu muammoning odatiy yechimi, bu jitter, ya'ni kutish intervaliga tasodifiylik qo'shish. Har bir klient aniq 2 soniya kutish o'rniga, 1 dan 3 soniyagacha tasodifiy vaqt kutadi, ya'ni quyidagi formula bo'yicha:
AWS da VP va Distinguished Engineer'i, Marc Brooker, bu mavzuda keng yozgan va ko'rsatganki, jitter nafaqat trafik zarbalarini kamaytiradi, balki butun tizimning tiklanish vaqtini (MTTR) sezilarli darajada yaxshilaydi. Chuqurroq o'rganmoqchi bo'lsangiz, uning AWS Arxitektura Blogidagi Exponential Backoff And Jitter maqolasi eng yaxshi manba. Shuningdek, Marc tomonidan yaratilgan distributed tizimlar simulyatoridan foydalanishingiz mumkin: https://stability-sim.systems/, bu yerda qayta urinishlar (retries) bilan bog'liq nosozlik rejimlarini vizualizatsiya qilishingiz mumkin.
@abdullaevdev
#distributedsystems #retries #saferetries #aws #mttr
3-qism: Yuklanish muammosi
πΊπΏ
1-qismda yuklanish ostida qayta urinishlar qisman nosozlikni to'liq nosozlikka aylantirishi mumkinligini ko'rdik. 2-qismdagi idempotentlik kalitlari to'g'rilik muammosini hal qiladi, lekin yuklanish muammosiga hech qanday yordam bermaydi. Qayta urinishlaringiz xavfsiz bo'lsa ham, ularni juda agressiv tarzda yuborish qiynalayotgan servisni ishdan chiqarishi mumkin.
Eksponensial kutish (Exponential backoff)
Ko'pchilik implementatsiyalar qilgan birinchi xato bu xatolikdan so'ng darhol qayta urinish. Agar servis haddan tashqari yuklama ostida bo'lsa, har bir millisekund qayta urinish vaziyatni yanada yomonlashtiradi. Eksponensial kutish har bir muvaffaqiyatsiz urinishdan keyin tobora uzoqroq kutishni anglatadi. Birinchi qayta urinish 1 soniyadan keyin, ikkinchisi 2 soniyadan keyin, uchinchisi 4 soniyadan keyin va hokazo, ya'ni quyidagi formula bo'yicha:
kutish=min(maks_kutish, dastlab_kutish * 2 ^ urinish). Bu pastki servisga yanada qiynalmasdan tiklanish uchun vaqt beradi.Momaqaldiroq podasi (Thundering herd)
Eksponensial kutishning o'zi yetarli emas. Minglab klientlar bir vaqtning o'zida qayta urinishni boshlashini tasavvur qiling, masalan, qisqa nosozlikdan keyin. Hatto kutish bilan ham, agar ularning barchasi bir xil jadvalga amal qilsa, ular bir xil intervallarda qayta urinadi. Pastki servis 1-soniyada trafik zarbasi, 2-soniyada yana bir zarba, 4-soniyada yana bir zarba oladi, yuklanish hamon sinxronlashgan holda qoladi.
Jitter
Bu muammoning odatiy yechimi, bu jitter, ya'ni kutish intervaliga tasodifiylik qo'shish. Har bir klient aniq 2 soniya kutish o'rniga, 1 dan 3 soniyagacha tasodifiy vaqt kutadi, ya'ni quyidagi formula bo'yicha:
kutish=tasodifiy(0, min(maks_kutish, dastlab_kutish * 2^urinish)). Qayta urinishlar vaqt bo'yicha taqsimlanadi, sinxronlashgan zarbalar yo'qoladi va pastki servis qayta-qayta zirvalar o'rniga tekis trafik ko'radi. AWS da VP va Distinguished Engineer'i, Marc Brooker, bu mavzuda keng yozgan va ko'rsatganki, jitter nafaqat trafik zarbalarini kamaytiradi, balki butun tizimning tiklanish vaqtini (MTTR) sezilarli darajada yaxshilaydi. Chuqurroq o'rganmoqchi bo'lsangiz, uning AWS Arxitektura Blogidagi Exponential Backoff And Jitter maqolasi eng yaxshi manba. Shuningdek, Marc tomonidan yaratilgan distributed tizimlar simulyatoridan foydalanishingiz mumkin: https://stability-sim.systems/, bu yerda qayta urinishlar (retries) bilan bog'liq nosozlik rejimlarini vizualizatsiya qilishingiz mumkin.
@abdullaevdev
#distributedsystems #retries #saferetries #aws #mttr
π₯5π3
πΊπΈ
As of September 1, it has been 4 years since I joined Amazon.
Laptops "retire" every 4 years at Amazon, so I got an email to pickup a new one. I was using MacBook Pro M1 Pro 32GB (with the tiny AWS sticker, yes I'm not a sticker guy π), and today I was given a box with a new MacBook Pro M5 Pro 48GB.
As the CTO of Amazon, Werner Vogels says: "Now, go build!" π
By the way, a new post on my 4th year at Amazon is in the works and coming out soon!
βββ
πΊπΏ
1-sentabr kuni Amazonda ish boshlaganimga 4-yil bo'ldi.
Amazonda ish noutbuklari har 4 yilda "pensiyaga" chiqadi, va menga yangisini kelib olib keting deb email yuborishdi. Men MacBook Pro M1 Pro 32GB ishlatar edim (rasmda kichik AWS stickeri bor, ha men stickerchi yigit emasman π), va bugun menga yangi qutida MacBook Pro M5 Pro 48GB berishdi.
Amazon'ning CTOsi Werner Vogels aytgandek: "Endi borib quring!" π
Ha aytgancha, Amazondagi 4-yilligim haqida yangi maqola tayyorlayabman, tez orada chiqadi!
@abdullaevdev
#amazon #aws #macbook #mac
As of September 1, it has been 4 years since I joined Amazon.
Laptops "retire" every 4 years at Amazon, so I got an email to pickup a new one. I was using MacBook Pro M1 Pro 32GB (with the tiny AWS sticker, yes I'm not a sticker guy π), and today I was given a box with a new MacBook Pro M5 Pro 48GB.
As the CTO of Amazon, Werner Vogels says: "Now, go build!" π
By the way, a new post on my 4th year at Amazon is in the works and coming out soon!
βββ
πΊπΏ
1-sentabr kuni Amazonda ish boshlaganimga 4-yil bo'ldi.
Amazonda ish noutbuklari har 4 yilda "pensiyaga" chiqadi, va menga yangisini kelib olib keting deb email yuborishdi. Men MacBook Pro M1 Pro 32GB ishlatar edim (rasmda kichik AWS stickeri bor, ha men stickerchi yigit emasman π), va bugun menga yangi qutida MacBook Pro M5 Pro 48GB berishdi.
Amazon'ning CTOsi Werner Vogels aytgandek: "Endi borib quring!" π
Ha aytgancha, Amazondagi 4-yilligim haqida yangi maqola tayyorlayabman, tez orada chiqadi!
@abdullaevdev
#amazon #aws #macbook #mac
β€23π13π₯7
Useless fact of the day: I deleted my IDEs
Last month I shipped 200+ PRs without an IDE (IntelliJ, VSCode, etc.) in my computer.
Turns out I was actually not paid to write text files on a black screen.
@abdullaevdev
#uselessfactoftheday #ai #ide #amazon
Last month I shipped 200+ PRs without an IDE (IntelliJ, VSCode, etc.) in my computer.
Turns out I was actually not paid to write text files on a black screen.
@abdullaevdev
#uselessfactoftheday #ai #ide #amazon
π₯17π6π―2π’1
Forwarded from Laziz Abdullaev
2-3 years ago people used to argue that LLMs (which usually refers to Chatbots) are stochastic parrots.
Now those debates are over. And it's not just because now we have stronger LLMs. It's because LLMs are augmented in an agentic system as a brain.
Remember when ChatGPT didn't know about the news today, or couldn't perform simple arithmetic?
Because they couldn't take actions (web search, coding, etc.) and they didn't have environmental presence (your computer, web browser, etc.)
If you put a human in an isolated room with no outside interaction and give them a book to study, they would learn the book content. But nothing more.
LLMs are not intelligent, but The System is close-to intelligent.
(c) Image credit to Stanford Online
@lazizabdullaev
Now those debates are over. And it's not just because now we have stronger LLMs. It's because LLMs are augmented in an agentic system as a brain.
Remember when ChatGPT didn't know about the news today, or couldn't perform simple arithmetic?
Because they couldn't take actions (web search, coding, etc.) and they didn't have environmental presence (your computer, web browser, etc.)
If you put a human in an isolated room with no outside interaction and give them a book to study, they would learn the book content. But nothing more.
LLMs are not intelligent, but The System is close-to intelligent.
(c) Image credit to Stanford Online
@lazizabdullaev
π6π―5β€2
Visit to Amazon HQ in Seattle, Washington πΊπΈ
Last week I flew across the Atlantic to the US west coast for a business trip to Amazon HQ in Seattle, Washington!
It was my first time there, and I got to meet our platform teams in person. The week was full of deep dives on topics like scalability and operational excellence, and I also presented two sessions.
About Seattle: it is amazing! For someone like me who loves nature, Seattle sits between the water and the mountains, and in the middle of it all is downtown, packed with tall glass buildings. I was at the famous Amazon Spheres, had some famous free bananas, walked through Pike Place Market (home of the original Starbucks) and visited the Space Needle.
Great week, great people. I shared my own ideas, picked up new ones, and I'm bringing it all back to Berlin!
@abdullaevdev
#amazon #seattle #us #aws #travel
Last week I flew across the Atlantic to the US west coast for a business trip to Amazon HQ in Seattle, Washington!
It was my first time there, and I got to meet our platform teams in person. The week was full of deep dives on topics like scalability and operational excellence, and I also presented two sessions.
About Seattle: it is amazing! For someone like me who loves nature, Seattle sits between the water and the mountains, and in the middle of it all is downtown, packed with tall glass buildings. I was at the famous Amazon Spheres, had some famous free bananas, walked through Pike Place Market (home of the original Starbucks) and visited the Space Needle.
Great week, great people. I shared my own ideas, picked up new ones, and I'm bringing it all back to Berlin!
@abdullaevdev
#amazon #seattle #us #aws #travel
β€9π₯5
Seattle (Washington shtati) dagi Amazon bosh ofisiga bordim πΊπΈ
O'tgan hafta Atlantika okeani orqali AQShning g'arbiy sohiliga uchib, Vashington shtatining Seattle shahridagi Amazon bosh ofisiga xizmat safari bilan bordim!
Bu mening u yerdagi birinchi safarim edi va platforma jamoalarimiz bilan jonli uchrashish imkoni bo'ldi. Hafta davomida scalability va operatsion mukammallik kabi mavzularda chuqur muhokamalar bo'ldi, men ham ikkita sessiyada prezentatsiya qildim.
Seattle haqida: u ajoyib! Men kabi tabiatni yaxshi ko'radigan inson uchun Seattle suv va tog'lar orasida joylashgan, uning markazida esa baland shisha binolarga to'la downtown joy olgan. Mashhur Amazon Spheres'da bo'ldim, mashhur bepul bananlarni tatib ko'rdim, Pike Place bozori (birinchi Starbucks shu yerda) bo'ylab yurdim va Space Needle'ga bordim.
Ajoyib hafta, ajoyib insonlar. O'z g'oyalarim bilan o'rtoqlashdim, yangilarini o'rgandim va hammasini Berlinga olib qaytyapman!
@abdullaevdev
#amazon #seattle #us #aws #travel
O'tgan hafta Atlantika okeani orqali AQShning g'arbiy sohiliga uchib, Vashington shtatining Seattle shahridagi Amazon bosh ofisiga xizmat safari bilan bordim!
Bu mening u yerdagi birinchi safarim edi va platforma jamoalarimiz bilan jonli uchrashish imkoni bo'ldi. Hafta davomida scalability va operatsion mukammallik kabi mavzularda chuqur muhokamalar bo'ldi, men ham ikkita sessiyada prezentatsiya qildim.
Seattle haqida: u ajoyib! Men kabi tabiatni yaxshi ko'radigan inson uchun Seattle suv va tog'lar orasida joylashgan, uning markazida esa baland shisha binolarga to'la downtown joy olgan. Mashhur Amazon Spheres'da bo'ldim, mashhur bepul bananlarni tatib ko'rdim, Pike Place bozori (birinchi Starbucks shu yerda) bo'ylab yurdim va Space Needle'ga bordim.
Ajoyib hafta, ajoyib insonlar. O'z g'oyalarim bilan o'rtoqlashdim, yangilarini o'rgandim va hammasini Berlinga olib qaytyapman!
@abdullaevdev
#amazon #seattle #us #aws #travel
π₯23π3