Ben Lesh is a senior software engineer at the very popular entertainment streaming company, Netflix. One of Ben’s projects at Netflix includes the development and maintenance of RxJS since it is heavily used by the company. In the eighth episode, Asynchronous and Event-Based Programming with RxJS we discuss everything from what is RxJS, how it was inspired, who is using it, and why you should use it over a few of the alternative methods. If you’ve ever heard of RxJava or Rx.NET, these projects share some similarities to RxJS.
For anyone that would rather read than listen, you can check out the following summary of the episode.
map transformations or filtering. Every time RxJS is notified of a new value in an observable, the line of events that you define are executed.
While promises and callbacks are useful, they are limited in what they can do. For example, promises wait for future values and are not lazy. When you receive a future value you can then manipulate it, but you can’t retry the request if it fails and you can’t cancel it if you need to move onto something else. With RxJS you have more power. You can subscribe to an observable or you can unsubscribe from an observable if you wish to cancel it. Observables are lazy so you can chain all your operations together and pass them around. They won’t do anything until you subscribe to them.
RxJS is heavily used by Netflix, the company that is actively contributing to the project. They need to be able to quickly and efficiently work with large streams of data and manipulate it as necessary. While Ben doesn’t explain the secret recipes on how Netflix is using it, he mentioned that it is a critical part of their business.
One of my current favorite frameworks, Angular, is using RxJS as a core dependency. I’ve stumbled upon RxJS when trying to do HTTP requests with Angular because the responses can be transformed using the
map operator and then further subscribed to using the
subscribe operator. However, HTTP is only a small piece to the Angular puzzle. While RxJS is used throughout the project, a great example he gave was in navigation. Because RxJS events can be canceled, unlike promises, outstanding events can be canceled during navigation. So if a user navigates somewhere, triggers a flow of events, then navigates away, the flow of events can be stopped instead of continuing to run. This adds performance gains to the application being developed.