Introduction to RSocket

RSocket is a binary byte stream transmission protocol, which is located at layers 5 and 6 of the OSI seven-layer model and corresponds to the application layer of the TCP/IP model. RSocket does not specify which underlying transport layer protocol must be used. Developers can use different underlying transport protocols, including TCP, WebSocket, and Aeron.

RSocket adopts binary format, which ensures efficient transmission and saves bandwidth. The R in RSocket stands for Reactive. Thus, through flow control based on reactive flow semantics, RSocket ensures that both parties in a message transfer do not collapse under the pressure of requests.

RSocket supports common responsive frameworks: RxJava, Spring Reactor.

2. RSocket features

Unlike the traditional Http protocol, RSocket supports multiple interaction models, such as streams and pushes, rather than simple requests/responses over an entire single connection.

RSocket also supports connection recovery by allowing streams to recover over different transport connections, which is especially useful when connections are frequently dropped, switched over, and reconnected. Especially in mobile scenarios.

RSocket features are as follows:

  • Message-driven: RSocket network traffic is asynchronous and models all traffic as multiple message flows over a single network connection and never synchronously blocks while waiting for a response.
  • Multiple interaction models: RSocket includes four interaction models: fire-and-forget, Request/Response, Request/Stream, and Channel.
  • Cancel: All streams (including requests/responses) support cancel to efficiently clean up server (responder) resources.
  • Recoverability: RSocket supports session recovery, allowing client/server sessions to be resumed over a new transport connection with a simple handshake.
  • Application Flow control: RSocket supports two forms of application-level flow control to help protect client and server resources from being overwhelmed: “Response flow”request(n)Asynchronous pull and rent.
  • Multi-language support: support Java, Kotlin, JavaScript, Go,.net, C++.
  • Transport Layer flexibility: RSocket allows developers to use different underlying transport layers depending on their environment, device capabilities, and performance requirements.
  • Efficiency vs. performance: Protocols that use network resources inefficiently (duplicate handshakes and connection Settings, reduced overhead, bloated message formats, and so on) can greatly increase perceived latency for the system. In addition, without flow control semantics, a poorly written module may overflow the rest of the system when the dependency service slows down, potentially leading to a retry storm that puts further stress on the system. Hystrix is a solution that attempts to solve the synchronous request/response problem. However, its overhead and complexity comes at a cost. RSocket reduces perceived latency and improves system efficiency by supporting non-blocking, duplex, asynchronous application communication and by flow control over multiple transmissions from any language. RSocket uses binary encoding to improve CPU and memory efficiency, avoiding handshakes and associated round-trip network overhead.

Terminology used by RSocket

  • Frame: Contains a single message for request, response, or protocol processing.
  • Fragment: Part of an application message that has been partitioned for inclusion in a frame.
  • Transport: transmits the RSocket protocol. Either WebSockets, TCP, or Aeron.
  • Stream: unit of action (request/response, etc.).
  • Payload: Flow messages (upstream or downstream). Contains data associated with the stream created by the previous request. In response flows and Rx, this is equivalent to an “onNext” event.
  • Complete: Terminal event sent on the stream indicating successful completion. In response flows and Rx, this is equivalent to an “onComplete” event.
  • Connection: instance of a transfer session between a client and a server.
  • Requester: The party that sends the request. A connection can have a maximum of two requestors, one in each direction.
  • Responder: The party that receives the request. A connection can have a maximum of two responders, one in each direction.

Related articles in the series:

RSocket learning part 2: HTTP VS WebSocket VS RSocket