The introduction

Responsive programming is still an era of chaos, with different definitions and implementations. A reactive declaration defines the characteristics that a reactive should satisfy. Spring5 has its own stack of reactive solution technologies, and reactiveX, which is widely known as rxJava, has its own understanding. Some say responsivity is event-based, others say it is based on data flow. Some people say that reactive programming is really just an API library for concurrent programming, and some people say that reactive programming is a programming idea, a programming paradigm. Technology circles have their own version of the story, as Little Brother Ma said: a technology, each state. Reactive programming is vague, vague, and exaggerated, making it difficult and painful for the average learner to get started.

The following explains reactive programming based on reactive declaration and reactiveX. If you have any objection, please feel free to discuss in the comments section.

What is reactive programming?

Is a reactive programming idea that uses asynchronous data flow programming. (from here)

Reactive Programming is based on the observer model and it is widely accepted that it provides non-blocking, asynchronous features for handling asynchronous scenarios, thereby avoiding callback hell and breaking Future’s limitations: hard to compose. (I don’t agree with this strength, java8’s completeFuture has been a great improvement).

In reactiveX, API libraries are provided for several languages that extend the observer mode to support data – or event-based drivers. Allows declaratively combined sequences of observers. Abstract synchronous and asynchronous programming into a unity.

Asynchronous programming and synchronous programming are shown in the following table. Different from the traditional pull type, responsive programming usually adopts push-type data transmission. The producer controls the consumption speed, but when the consumption speed is insufficient, it can also prompt the producer to reduce the production speed (backPressure), which will be described below.

Reactive Programming is usually Functional, but it’s designed to simplify the bloatiness of object-oriented syntax. The core of Reactive Programming is Reactive, but with some of the features of Functional, not Functional Reactive Programming, which is something completely different.

Responsive declaration

What characteristics should a responsive system have

When a system is Responsive, Resilient, Elastic, and Message Driven. We call such a System a Reactive System.

As shown in the figure, the value of reactive programming lies in (1) ease of writing and maintenance (especially asynchronous programming) and (2). Be responsive.

What is just-in-time response? Whether something goes wrong, whether it’s power outages, network jitter, or code bugs, it responds in a timely manner and provides adequate availability.

Reactive declarations simplify handling of errors by treating exceptions as messages, where errors can be treated simply as exceptions.

What is elasticity? Resilience?

Elasticity means that there is no difference in the throughput and responsiveness of the system under different loads. Responsive through scaling algorithm, so that the system has no resource contention point and central bottleneck.

Resilience is the ability to replicate, contain, isolate, and delegate in the event of system failures, such as power outages, hardware failures, and resource exhaustion.

Message-driven or event-driven?

Messages are data and events are signals. Messages contain more information.

For message-driven systems, if no message comes, the receiver asynchronously non-blocking waits for the thread to arrive (sleep).

For event-driven systems, callbacks are often used.

Message-driven design is recommended in reactive declarations because event-driven systems are difficult to bounce back from:

For event-driven systems, when the process is in place and listeners are set up to respond to and transform the results, these listeners will typically handle success or failure directly and report the results of execution to the original client.

These listeners respond to component failures in order to restore its normal function, and on the other hand, deal with failures that are not tied to transient client requests, but affect the health of the entire component.

Discussion of responsive programming

Why use observer mode

Using this pattern frees developers from callback hell. ReactiveX improves code readability by using streams to unify asynchrony, synchronization, and combine operations through subscribers.

What is callback hell? In fact, when the callback function needs to be combined, it often makes the code complexity greatly increased, the code readable greatly reduced phenomenon.

ReactiveX’s observer mode is flexible, supporting both push and pull.

What is backPressure?

In fact, back pressure translation is not good, called back pressure is more appropriate. There is an explanation of backPressure on zhihu, which I think is very good. BackPressure is actually just a phenomenon, but backPressure in responsive programming is actually a kind of processing strategy to solve the problem when consumption fails to catch up with production. Some make producers push slowly, some directly abandon…

In the process of data flow transmission from upstream producers to downstream consumers, upstream production speed is higher than downstream consumption speed, resulting in downstream Buffer overflow, which is called Backpressure.

Personal feelings

When I was still a student, I often heard people talk about responsive programming and Webflux. At that time, I was confused by various new technologies and read a few relevant introductions. Then I heard how good and advanced responsive programming was touted by various blog articles, and I felt that I must learn it.

After work, I found that the actual production actually does not need to be so advanced things, most of the time the on-line system stability is the most important. Domestic Java8 is still popular, a lot of people java8 characteristics have not been understood, but still in the job to support a day.

For developers, don’t be fooled by all the “tech marketing” on the Internet. Think twice before you learn a new technology. What codes, what technologies, what frameworks, are just hammers in the hands of migrant workers on the Internet, not the new and fancy hammers, the better, can solve the actual work content on the line.

Sometimes rather than to learn all kinds of new technology and new framework, watching movies, shopping than with family, we are not the screws of the Internet, we are human beings, just as capitalism times, most people are alienation becomes a “tool”, but we all have our own lives, their families, friends, everyone is different, have their own life.

In short, there is a wide variety of responsive programming in the market, with many definitions and insufficient merit arguments.

The related documents

  1. reactivex.io/intro.html
  2. GitHub rxjava
  3. Reactive-Programming- A technique – expressed separately
  4. Responsive declaration
  5. Reactive declaration vocabulary