Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Design for Retry (Oneshot Budapest)
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Aria Stewart
November 21, 2014
Programming
71
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Design for Retry (Oneshot Budapest)
Aria Stewart
November 21, 2014
More Decks by Aria Stewart
See All by Aria Stewart
Nuts and Bolts of Internationalization
aredridel
0
240
Design for Retry (Nodevember)
aredridel
0
59
Other Decks in Programming
See All in Programming
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
350
関数型プログラミングのメリットって何だろう?
wanko_it
0
190
【やさしく解説 設計編・中級 #1】一つの車に、運転手は一人 ~ある倉庫システムの事例から~
panda728
PRO
0
190
共通化で考えるべきは、実装より公開する型だった
codeegg
0
270
AIが無かった頃の素敵な出会いの話
codmoninc
1
210
PHPだって関数型したい 〜できること、できないこと〜 / fp-in-php
jsoizo
1
240
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
2
630
GDG Korea Android: 2026 I/O Extended ~ What's new in Android development tools
pluu
0
110
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
390
Claude Team Plan導入・ガイド
tk3fftk
0
220
AIエージェントで 変わるAndroid開発環境
takahirom
2
710
AWS CDK を「作」ってみた 〜フルスクラッチで見えた CDK の裏側〜 / aws-cdk-from-scratch
gotok365
3
500
Featured
See All Featured
Measuring & Analyzing Core Web Vitals
bluesmoon
9
900
Being A Developer After 40
akosma
91
590k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Building an army of robots
kneath
306
46k
Utilizing Notion as your number one productivity tool
mfonobong
4
450
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
420
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Transcript
Design for Retry: Microservices, REST, and why Idempotency is the
only way to scale I'm Aria Stewart, that's @aredridel just about everywhere. I'm here thanks to PayPal. I work on the open source Kraken.js framework.
I'm going to talk about errors. It's going to be
okay.
if (err) { alert(err.message); } else { doMyThing(); }
We all know HTTP
2xx OK 3xx Go elsewhere 4xx Tell user what they
did wrong 5xx Bail out and log an error I'd call this Error avoidance
You can't avoid errors
Here's the secret Handle errors instead
4xx Tell the user what they did wrong 5xx Save
that request and do something with it later.
Retry it 5xx are errors the requestor can handle
But you can't just do things twice? We must make
operations idempotent
Idempotency Repeated actions have no effect, give the same result
This means being smart about IDs. Don't recycle! Check if things are already done. They are? Just give the same answer again.
Causes! —database down —bug in a service —Deploy in progress
—power failure —kicked a cable —Network congestion —Capacity exceeded —Microbursts
—Tree fell on the data center —earthquake —tornado —birds, snakes
and aeroplanes —Black Friday —Slashdot effect —Interns —QA tests —DoS attack
You need a queue
Lots of ways to do it Database on each node.
Maybe LevelDB? Log file Queue server
gearman Queues built in There are many alternatives, but gearmand
is very simple. The memcache of job queues.
Three statuses: —OK (Like 200) —FAIL (Like 400) —ERROR (Like
500)
design so ERROR can be retried.
gearmand automatically tries a job ERROR again. And again. And
again.
If it isn't sure it worked? Tries it again.
You cannot know if an error is a failure.
Error handling gets simpler —Exception? ERROR. —Database down? ERROR. —Downstream
service timeout? ERROR. Maybe you retry right away.
How many of you have used a job queue?
You have used a job queue
Let me tell you about one TRILLIONS of messages MILLIONS
of nodes 100% availability (at least partial) for years. 32 years. Resilient to MILLIONS of bad actors. It is attached to the most malicious network.
EMAIL. 250 OK 4xx RETRY 5xx Fail
Responsibility for messages 250 - accept responsibility 4xx - reject
responsibility 5xx - return responsibility
reject responsibility. If there's an error? Fail fast. The requester
can retry.
Fail fast. Queue work you can't reject. Reject everything you
can if there is an error.
You need a smart client. Keeps outstanding requests. Resubmit. Try
a different server! Try a second queue service. Maybe have a fallback plan.
Smart Clients on the device Toto, we're not in AWS
anymore.
Ever lose an email because you've been logged out?
Latency + Mutable state = Distributed system CAP Theorem Applies!
C = Consistency If there's state that one part knows
of that another doesn't? That's inconsistency.
Job queues are controlled inconsistency.
Ever try to write email on the web while not
on the Internet? It's cloud easy!
This is really good for offline-first design! Being offline is
the ultimate retriable error.
Some ideas
Use your queue as a place to measure for system
sizing
Queue things in localStorage
Use third-party storage
Integrate third-party services with this approach.
Use different strategies for available resources vs contended
Thank you! I hope you have lots of ideas queued
up. Save your ideas and unspool them onto Twitter when you get home. Let me know if this changed how you think about designing applications!