Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 2.02 KB

04_backuprequests.adoc

File metadata and controls

29 lines (22 loc) · 2.02 KB

Backup requests pattern with RxJava and Java 8

WordCountWithBackupRequests

The backup requests pattern is a technique to deal e.g. with "long tail latencies". See e.g. https://www.typesafe.com/blog/reactive-revealed-part-1-of-3-async-nio-back-pressure-and-the-message-driven-vs-event-driven-approach (slide 77 and following) for an introduction.

How to implement this with RxJava?

  • In an existing classic, synchronous codebase…​ sometimes a call is "slow"

  • Solution: The relevant call (imagine calling a remote system) is wrapped with an rx.Observable and executed in a separate thread

  • Using the timer operator we setup a delayed backup call

  • Using the merge operator we merge the two observables

  • And the first operator emits the "faster" result and does the auto-unsubscribe resulting in cancelling the "slower" call

Warning: