Video and slides synchronized, mp3 and slide download available at URL http://bit.ly/1VmbI3t.
Nitesh Kant describes how embracing asynchrony in the Netflix applications, from networking to business processing, creates gracefully degrading and highly resilient applications. Filmed at qconsf.com.
Nitesh Kant is an engineer in Netflix’s Edge Gateway team, working on Netflix’s asynchronous Inter Process Communication stack. He is the author of RxNetty which forms the core of this stack and is currently moving Zuul to this new architecture.
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Crossroads of Asynchrony and Graceful Degradation
1. Crossroads of asynchrony
and graceful degradation
Nitesh Kant,!
Software Engineer, !
Netflix Edge Engineering.!
!
@NiteshKant
2. InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
http://www.infoq.com/presentations
/netflix-asynchronous-apps
3. Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon San Francisco
www.qconsf.com
14. !
public Movie getMovie(String movieId) {!
Metadata metadata = getMovieMetadata(movieId);!
Bookmark bookmark = getBookmark(movieId, userId);!
Rating rating = getRatings(movieId);!
return new Movie(metadata, bookmark, rating);!
}!
Disclaimer: This is an example and not an exact representation of the processing
15. Synchronicity
!
public Movie getMovie(String movieId) {!
Metadata metadata = getMovieMetadata(movieId);!
Bookmark bookmark = getBookmark(movieId, userId);!
Rating rating = getRatings(movieId);!
return new Movie(metadata, bookmark, rating);!
}!
Disclaimer: This is an example and not an exact representation of the processing
16. The bigger picture Price of being synchronous?
!
public Movie getMovie(String movieId) {!
Metadata metadata = getMovieMetadata(movieId);!
Bookmark bookmark = getBookmark(movieId, userId);!
Rating rating = getRatings(movieId);!
return new Movie(metadata, bookmark, rating);!
}!
Disclaimer: This is an example and not an exact representation of the processing
17. In a microservices world
Edge Service
Ratings ServiceVideo Metadata Service
Bookmarks Service
Disclaimer: This is an example and not an exact representation of the processing
18. In a microservices world
Edge Service
Server threadpool
Thread
Thread
Thread
Thread
Thread
getMovieMetadata(movieId)
Disclaimer: This is an example and not an exact representation of the processing
19. In a microservices world
Edge Service
Server threadpool
Thread
Thread
Thread
Thread
Thread
getMovieMetadata(movieId)
getBookmark(movieId, userId)
Disclaimer: This is an example and not an exact representation of the processing
20. In a microservices world
Edge Service
Server threadpool
Thread
Thread
Thread
Thread
Thread
getMovieMetadata(movieId)
getBookmark(movieId, userId)
getRatings(movieId)
Disclaimer: This is an example and not an exact representation of the processing
24. Disclaimer: This is an example and not an exact representation of the processing
Ratings Service
Edge Service
Server threadpool
Thread
Thread
Thread
Thread
Thread
getRatings(movieId)
25. Disclaimer: This is an example and not an exact representation of the processing
Edge Service
getRatings(movieId)
Server threadpool
Thread
Thread
Thread
Thread
Thread
26. Edge Service
Disclaimer: This is an example and not an exact representation of the processing
getRatings(movieId)
Server threadpool
Thread
Thread
Thread
Thread
Thread
30. Managing client thread pools
Disclaimer: This is an example and not an exact representation of the processing
Client Threadpool
Thread
Thread
Thread
Thread
Thread
36. Clients have become our babies
Edge Service
Server threadpool
Thread
Thread
Thread
Thread
Thread
getMovieMetadata(movieId)
Disclaimer: This is an example and not an exact representation of the processing
Client Threadpool
Thread
Thread
Thread
Thread
Thread
Client Threadpool
Thread
Thread
Thread
Thread
Thread
Client Threadpool
Thread
Thread
Thread
Thread
Thread
getBookmark(movieId, userId)
getRatings(movieId)
61. This can not adapt…
!
public Movie getMovie(String movieId) {!
Metadata metadata = getMovieMetadata(movieId);!
Bookmark bookmark = getBookmark(movieId, userId);!
Rating rating = getRatings(movieId);!
return new Movie(metadata, bookmark, rating);!
}!
Disclaimer: This is an example and not an exact representation of the processing
64. What should be async?
Edge Service
Video Metadata Service
65. What should be async?
Edge Service
Video Metadata Service
getMovieMetadata(movieId)
getBookmark(movieId, userId)
getRatings(movieId)
Application logic
66. What should be async?
Edge Service
Video Metadata Service
getMovieMetadata(movieId)
getBookmark(movieId, userId)
getRatings(movieId)
I/O
I/O
I/O
Application logic
I/O
67. What should be async?
Edge Service
Video Metadata Service
getMovieMetadata(movieId)
getBookmark(movieId, userId)
getRatings(movieId)
I/O
I/O
I/O
Application logic
I/O
Network protocol
74. Function composition
!
public Movie getMovie(String movieId) {!
Metadata metadata = getMovieMetadata(movieId);!
Bookmark bookmark = getBookmark(movieId, userId);!
Rating rating = getRatings(movieId);!
return new Movie(metadata, bookmark, rating);!
}!
75. Function composition
Composing the processing !
of a method into a single control point.
public Observable<Movie> getMovie(String movieId) {!
return Observable.zip(getMovieMetadata(movieId),!
getBookmark(movieId, userId),!
getRatings(movieId),!
(meta,bmark,rating)->new Movie(meta,bmark,rating));!
}!
76. Composing the processing !
of a method into a single control point.
Flow & Lifecycle Control
with
77. What should be async?
Edge Service
Video Metadata Service
getMovieMetadata(movieId)
getBookmark(movieId, userId)
getRatings(movieId)
I/O
I/O
I/O
Application logic
I/O
Network protocol
79. I/O
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
Eventloops = f (Number of cores)
80. I/O
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
Connections multiplexed !
on a !
single eventloop.
81. I/O
Disclaimer: This is an example and not an exact representation of the processing
Edge Service
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
82. I/O
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
Clients share the eventloops!
with!
the server.
83. I/O
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
All clients share !
the!
same eventloop
84. Composing the processing !
of a service into a single control point.
Flow & Lifecycle Control
with
85. What should be async?
Edge Service
Video Metadata Service
getMovieMetadata(movieId)
getBookmark(movieId, userId)
getRatings(movieId)
I/O
I/O
I/O
Application logic
I/O
Network protocol
98. Composing the processing !
of the entire application into a single control point.
Flow & Lifecycle Control
with
99. Edge Service
Video Metadata Service
Rating service C* store
C* store
/movie?id=123
Disclaimer: This is an example and not an exact representation of the processing
100. Edge Service
Video Metadata Service
Rating service C* store
C* store
/movie?id=123
Disclaimer: This is an example and not an exact representation of the processing
Observable<Movie>
103. Latency
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
104. Latency
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
Impact is localized to the
connection.
105. Latency
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
Impact is localized to the
connection.
An outstanding request has
little cost.
106. An outstanding request has little cost.
GET /movie?id=1 HTTP/1.1
HTTP/1.1 200 OK!
…
} Any stored state between!
request - response!
is costly.
108. Overload & Thundering Herds
Edge Service
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
Disclaimer: This is an example and not an exact representation of the processing
Reduce work done !
when overloaded
109. Overload & Thundering Herds
Edge Service
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
Disclaimer: This is an example and not an exact representation of the processing
Reduce work done !
when overloaded
Stop accepting!
new requests.
128. Threadpools?
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
I/O!
is!
non-blocking.
129. Threadpools?
Edge Service
Disclaimer: This is an example and not an exact representation of the processing
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
Application code !
is!
non-blocking.
130. Threadpools?
Disclaimer: This is an example and not an exact representation of the processing
Edge Service
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
No blocking/Waiting => Only CPU work
131. Threadpools?
Disclaimer: This is an example and not an exact representation of the processing
Edge Service
Eventloop (Inbound)
Connection
Connection
Connection
Connection
Connection
getMovieMetadata(movieId)
Eventloop (Outbound)
Connection
Connection
Connection
Connection
Connection
No blocking/Waiting => Only CPU work
So,
Eventloops = # of cores
137. Case for timeouts?
Read Timeouts Thread Timeouts
✤ Useful in unblocking threads
on socket reads.
✤ Business level SLA.
✤ Unblock the calling thread.
138. Case for timeouts?
Read Timeouts Thread Timeouts
✤ Useful in unblocking threads
on socket reads.
✤ Business level SLA.
✤ Unblock the calling thread.
X X
As there are no blocking calls.X
139. Case for timeouts?
Read Timeouts Thread Timeouts
✤ Useful in unblocking threads
on socket reads.
✤ Business level SLA.
✤ Unblock the calling thread.
140. Business level SLA
Edge Service
Video Metadata Service
Disclaimer: This is an example and not an exact representation of the processing
141. Business level SLA
Edge Service
Video Metadata Service
Disclaimer: This is an example and not an exact representation of the processing
Rating service C* store
C* store
142. Business level SLA
Edge Service
Video Metadata Service
Disclaimer: This is an example and not an exact representation of the processing
Rating service C* store
C* store
143. Business level SLA
Edge Service
Video Metadata Service
Disclaimer: This is an example and not an exact representation of the processing
Rating service C* store
C* store
Thread timeouts are pretty invasive at every level
144. Business level SLA
Edge Service
Video Metadata Service
Disclaimer: This is an example and not an exact representation of the processing
Rating service C* store
C* store
Thread timeouts are pretty invasive at every level
Do we need them at every step?
145. Edge Service
Video Metadata Service
Rating service C* store
C* store
/movie?id=123
Disclaimer: This is an example and not an exact representation of the processing
146. Edge Service
Video Metadata Service
Rating service C* store
C* store
/movie?id=123
Business timeouts are !
for !
a client request.
Disclaimer: This is an example and not an exact representation of the processing
147. Edge Service
Video Metadata Service
Rating service C* store
C* store
/movie?id=123
Disclaimer: This is an example and not an exact representation of the processing
148. Edge Service
Video Metadata Service
Rating service C* store
C* store
/movie?id=123
X
Disclaimer: This is an example and not an exact representation of the processing
149. Edge Service
Video Metadata Service
Rating service C* store
C* store
/movie?id=123
X
X
X
X
X
Disclaimer: This is an example and not an exact representation of the processing
153. Edge Service
Video Metadata Service
Rating service C* store
C* store
Disclaimer: This is an example and not an exact representation of the processing
Request Leases
Cancellations
Observable<Movie>
154. Edge Service
Video Metadata Service
Rating service C* store
C* store
Disclaimer: This is an example and not an exact representation of the processing
Request Leases
Cancellations
Observable<Movie>
155.
156. !
public Movie getMovie(String movieId) {!
Metadata metadata = getMovieMetadata(movieId);!
Bookmark bookmark = getBookmark(movieId, userId);!
Rating rating = getRatings(movieId);!
return new Movie(metadata, bookmark, rating);!
}!
public Observable<Movie> getMovie(String movieId) {!
return Observable.zip(getMovieMetadata(movieId),!
getBookmark(movieId, userId),!
getRatings(movieId),!
(meta,bmark,rating)->new
Movie(meta,bmark,rating));!
}!