Q&A
Creating Reactive Applications in .NET
In modern applications, data is being retrieved in asynchronous, real-time streams, as the days of traditional pull requests where the clients asks for data from the server are becoming a thing of the past.
One key aspect of this approach is that reactive applications incorporate push notifications -- using frameworks like Rx and SignalR -- to provide real-time updates to users.
To spread the word about this modern technique, renowned developer, author and speaker Jason Bock will present an intermediate-level session titled "Creating Reactive Applications in .NET" at Microsoft HQ in Redmond, Wash., on Aug. 7 as part of the Visual Studio Live! developer conference series.
In the 75-minute session, Bock will explain concepts such as how async streams, a proposed C#8 feature, can be used to consume data streams, and more. Specifically, attendees are promised to:
- Understand the benefits of reactive programming
- Use frameworks such as Rx and SignalR in native and web applications
- See new C# features to empower reactive development
We caught up with Bock, who has more than 25 years of experience working on a number of business applications using a diverse set of frameworks and languages, in a short Q&A.
VisualStudioMagazine: What inspired you to present a session on this topic?
Bock: I've always been interested in distributed systems, as well as concurrent programming models. With reactive programming, you lean heavily on the ability to process and send messages in a manner that reduces the number of resources a program uses. When .NET first came out, there wasn't a lot of support to assist a developer in writing reactive applications. Over time, as features were added to C# and reactive-based libraries were created, this started to become easier to do. I spent some time writing code using reactive concepts and I wanted to share that knowledge with others.
Can you provide an overview of the key advantages of reactive programming over traditional request-response models in application development?
The main advantage is being able to defer work until a later point in time.
"The main advantage is being able to defer work until a later point in time."
Jason Bock, MVP (C#), Staff Software Engineer at Rocket Mortgage
If you think about an application that lets you order products, pressing the "Order" button will immediately return. You don't wait until the products show up at your residence. Order fulfillment is a complex process, and being able to split that process up into discrete parts helps in terms of scalability. Once a particular action is done, it can post a message to a queue, which the next function can pick up asynchronously.
In the context of asynchronous data streams, how do push notifications enhance user experience compared to traditional pull-based methods?
Pull-based techniques are fine if you know that there will be a set of data to retrieve based on the activity you need to do. For example, if you want to retrieve the first 10 employees where their last name starts with the letter "S," you write that query, submit it to your database, and get the data back. However, there are lots of times when you don't know how much data there will be, or when it will show up. Notifications are a great example of this. We all get e-mail throughout the day, but we don't know how much or when it'll show up. This is where reactive programming shines. These notifications are only displayed once they're retrieved, rather than requiring the user to constantly poll for new messages. Now, it's possible that an application simulates reactive programming through polling, but hopefully they're modernized to use push-based programming techniques!
Could you delve into how the proposed async streams feature in C#8 could revolutionize data stream consumption in .NET applications?
At this point, this is no longer a proposal; asynchronous streams work in C# in 2024. What's nice is that you only need to add one keyword to your "foreach" enumeration, and that is "await". If the object you're enumerating implements IAsyncEnumerable<T>, the iteration will work in an asynchronous fashion. Since this is all based on standard async/await/Task functionality that has existed in C# for a long time, everything flows naturally.
With the integration of frameworks like Rx and SignalR, what architectural changes should developers anticipate in their application designs?
A key difference when thinking reactive is to break up the "everything at once" mindset. This means that when an event happens in an application -- for example, a user pressing a button -- the actual work related to that event does not have to happen at that moment in time. In fact, deferring that work will change the perception of responsiveness, because the application will return quicker. However, developers will also need to put some thinking time around reporting status. What happens if some part of the work fails? The user will probably be long gone at that point. Reactive programming breaks up workflows in an asynchronous way, and it can be a challenge to produce solutions that provide users with meaningful feedback at a later point in time.
How do you see reactive programming evolving in the .NET ecosystem, especially with upcoming features in C# and .NET frameworks?
The main challenge will be the Rx framework itself. It has changed ownership in recent history, and hopefully this will reignite community involvement and interest. That said, there are some significant challenges ahead due to technical decisions made in the past, and it may take some time to overcome this debt and build momentum.
For developers new to reactive programming, what resources or starting points would you recommend to ease their learning curve?
There are two sites I'd recommend visiting. The first one is ReactiveX. This has a substantial amount of information on reactive programming that is language-agnostic. The other one is the GitHub repository for Rx. This has recently been updated to include a free version of a great book called "Introduction to Rx.NET."
Note: Those wishing to attend the conference can save hundreds of dollars by registering early, according to the event's pricing page. "Register for VSLive! at Microsoft HQ by the Super Early Bird deadline of June 7 to save up to $400 and secure your seat for intensive developer training at Microsoft HQ in Redmond!" said the organizer of the developer conference, which is being presented by the parent company of Visual Studio Magazine.
About the Author
David Ramel is an editor and writer at Converge 360.