Reactive programming describes a design paradigm that relies on asynchronous programming logic to handle real-time updates to otherwise static content. It provides an efficient means -- the use of automated data streams -- to handle data updates to content whenever an inquiry is made by a user.
Data streams used in reactive programming are coherent and cohesive collections of digital signals created on a continual or near-continual basis. These data streams are sent from a source -- such as a motion sensor, temperature gauge or a product inventory database -- in reaction to a trigger. That trigger could be any of the following:
- An event, such as keystrokes and mouse clicks, or system-generated, such as program loading, running out of memory and errors
- A call, a function invoking a routine
- A message, an information unit that the system sends back to the user or system operator with information about the status of an operation, an error, failure, or other condition.
For example, consider the simple expression a = b + c. If b gets updated in the code base, and we want a to be always be updated whenever b or c is updated we need to employ some functions that track the changes in the application state, and whenever b or c is updated it updates a, as well. Those functions are expressed using reactive programming.
Jonas Bonér, Dave Farley, Roland Kuhn, and Martin Thompson, authors of the Reactive Manifesto, characterize systems created by reactive programming as such:
- Responsive, providing rapid and consistent response times
- Resilient, meaning that the system stays responsive despite hardware or software failures
- Elastic, wherein the system remains responsive in varying workloads
- Message driven, relying on asynchronous message-passing
Message-based systems in this sense are communications networks in which the sender of the data targets a specific recipient, such as an online order or an inquiry). Message-based systems are sometimes contrasted with event-based systems, in which a trigger, such as a change in inventory or the rise of a stock price, causes the source to send data to all subscribers.