The State of RSocket in JavaScript

RSocket is an exciting new advancement in the application protocol space with decent adoption and support in the Java ecosystem, mainly due to contributions from companies such as Pivotal, and leading support in the popular Spring framework. With respect to JavaScript, RSocket hasn't quite picked up the same level of popularity or achieved as other protocols, such as GraphQL.

Stiff Competition

Let's compare RSocket's search popularity with GraphQL's to help gauge popularity of each protocol.

RSocket

In the below graph, we see that RSocket's search popularity only started picking up steam in late 2018.

RSocket Search Popularity

Source: Google Trends

GraphQL

In contrast, GraphQL has experienced a much steeper increase in search popularity, starting in 2016.

GraphQL Search Popularity

Source: Google Trends

Drawing Parallels

If we draw a parallel between search popularity and industry adoption, RSocket has yet to experience the same search popularity growth as GraphQL, signifying that it hasn't adopted the same level of adoption.

RSocket vs GraphQL search popularity

GraphQL in red. RSocket in blue.


Source: Google Trends

Popularity and Adoption

One can easily contribute the popularity of GraphQL to its conception at Facebook and Facebook's opensource contributions having high visibility in the JavaScript space. Additionally, the investment into the GraphQL ecosystem from startups such as Apollo GraphQL have paid dividends into popularizing GraphQL. If RSocket were to gain popularity with large enterprise companies, as well as an engaged audience of JavaScript developers, I believe it could help RSocket experience similar adoption.

RSocket's Ecosystem is Undeveloped in JavaScript

In JavaScript, most developers have become accustomed to leveraging open source packages to solve a wide range of common problems, and it's never been a better time to avoid reinventing the wheel. However, being that there is only a single reference implementation of RSocket and no well-established supporting libraries, if you expect to be able to npm install your way to victory, you're going to have a bad time with RSocket.

Southpark super cool ski instructor meme

Support for RSocket in JavaScript

There exists enough library support to build something with RSocket & JavaScript, however, when it comes to running an application in production, and you start considering monitoring, telemetry, and other needs, your mileage may vary.

rsocket-js

rsocket-js is the primary reference implementation of RSocket for JavaScript. The library provides the low level base implementations for several transports, as well as a Reactive Streams implemention.

When building an application, developers will find it is much more practical to consume an abstraction library, such as rsokcet-rpc-js, rather than consume rsocket-js directly. However, library authors would likely spend a majority of their time interfacing with rsocket-js directly.

Project Ownership

At first glance, it can be difficult to determine the primary maintainers of the rsocket-js project. The contributions as of late have primarily been from engineers who do not appear to be associated with Facebook, however, several of the licenses in the repository reference Facebook, and new contributors to the project are expected to accept the Facebook OSS agreement. Based on this, it appears that Facebook may not be taking a leading role in the libraries continued development, even if they did bootstrap and get the library off the ground initially. It is also important to note that the project has received varying levels of contribution from engineers at companies such as Pivotal and Netifi, as well as contributors from the open source community.

Uncertainty

The Java implementation of RSocket for Java (rsocket-java) has received heavy and continued contribution from engineers at established well known companies, such as Netflix and Pivotal. This investment by leaders in the Java OSS space provides consumers of rsocket-java with a certain level of confidence that the project has a long life ahead of it, and as such, could feel more comfortable betting their project, and possibly their business of the technology. In contrast, it is uncertain if rsocket-js has a clear set of core maintainers, a defined road map, or is being used by any large companies.

rsocket-rpc-js

rsocket-rpc-js is an abstraction library which consumes rsocket-js, and in practical terms, is likely the interface that most applications or developers would consume when working with RSocket in JavaScript.

rsocket-rpc-js - "The Standard RPC implementation for RSocket" in JavaScript.

In addition to exposing the reactive streams implementation behind service interfaces that will be familiar to traditional OOP programmers, the library also ties in nicely with RSocket message brokers that facilitate message routing, which can be core to any distributed messaging system.

Opinionated

RPC style client and server implementations are generally opinionated about the interfaces they expose and how messages are framed/formatted.

In contrast to a restful API where a consumer requests a User resource by invoking an HTTP GET request to /users/1, where 1 is the user ID, in an RPC API it would more common to invoke a HTTP POST request to /UserService/GetUserById and include in the request body the ID of the user { "userId": 1 }. rsocket-rpc-js encourages these types of RPC patterns and interfaces. A method following this pattern could have a signature similar to the following: getUserById(Number: id): Single<User>.

Tooling

Opinionated APIs and specifications empowers tooling to be built which further standardizes integrations without requiring developers to work around new ideas that present their own unique challenges. For instance, because rsocket-rpc-js and other RSocket RPC implementations follow an established spec, it is possible to generate source code for clients, servers, and message payloads in a number of languages by leveraging common tools and interchange formats such as protoc and protobuf.

An example of consuming a generated client service produced by protoc when combined with the rsocket-rpc-protobuf protoc plugin would be similar to the below:

const request = new HelloRequest();
request.setName('John Doe');
helloServiceClient.sayHello(request).subscribe({
    onComplete: (response) => {
        console.log(`HelloService.sayHello response received with message: ${response.getMessage()}`);
    },
    onError: (error) => {
        console.log(`HelloService.sayHello response received with error: ${error.name}`);
        console.error(error);
    }
});

In the above example a service has been implemented that exposes a method that utilizes the "Request Response" flow (review the list of flows on the rsocket.io website), and this helloServiceClient implementation can be generated by protoc when given a protobuf definition such as:

syntax = "proto3";

service HelloService {
    rpc SayHello (HelloRequest) returns (HelloResponse) {}
}

message HelloRequest {
    string name = 1;
}

message HelloResponse {
    string message = 1;
}

Platforms

In addition to promoting the creation of tooling, a standardized opinionated specification also supports the creation of platform services and solutions, such as netifi, which is a language agnostic broker for RSocket that aims to solve many of the common service mesh orchestration challenges.

rsocket-flowable

rsocket-flowable provides an implementation for Reactive Streams in JavaScript, and is deeply ingrained into both rsocket-js and rsocket-rpc-js. Learning the rsocket-flowable API, and what it means to work with Reactive libraries and paradigms is going to be paramount to successfully working with rsocket-js and rsocket-rpc-js.

If you are familiar with RxJS, then rsocket-flowable will likely feel familiar to you. If you are not familiar with RxJS, or reactive programming paradigms, then you could experience a somewhat steep learning curve.

What to Expect Next

While the bulk of ongoing development appears to be centered around the Java and C++ implementations of RSocket, it is my hope that the JavaScript implementation will continue to receive updates and additions to meet the full RSocket spec, but only time will tell.

If you are passionate about RSocket and a seasoned JavaScript developer, now may be a good time to get involved with the project to leave your mark and assist in its continuity. If contributing to the project is not your cup of tea, then sharing this article and RSocket with your friends, coworkers, and on your social networks would be a great way to increase RSocket's visibility in the JavaScript community.

Drop me a comment below, or tweet me on Twitter and let me know if this is the first you are hearing of RSocket, or if you are also closely watching its development, as I am.