Four Tools for Exposing an API in a Reactive Way

A light overview of four tools that can help development teams expose APIs in their microservice applications while adhering to reactive programming principles.

In the modern digital world, a system which cannot talk to other systems or does not allow other systems to talk to itself is bound to fail. A lot of organizations that we work with, be it large banks, healthcare institutions, travel booking, predictions, or industrial analysists, would like to expose their ecosystem through an API so that it is available as a platform for other companies and products to consume and innovate on.

In the reactive world, we have a few easily available options based on this need. As you would expect, these are powered by Akka, the amazing technology which drives games like Fortnite.

Let us look at a summary of the options that we have.

The Reactive API Ecosystem

  1. Play – Use this if you are building a new REST API and are coming from Spring MVC or your system involves a Web UI.
  2. Akka HTTP – If you would like to wrap an existing application/system with API endpoints, this framework makes it simple and flexible.
  3. Lagom – If you need a full powered microservices system which comes bundled with the goodies like ES/CQRS and best practices like DDD, etc,

Of course, you can use Akka, Akka Streams, Alpakka, Akka gRPC, etc. with any of these.

Now let us look at each one of them in a little more detail

Play

  • Built on top of Akka and Akka HTTP.
  • Supports building HTML based user interfaces.
  • Based on the MVC model.
  • Used to build CRUD style applications, API gateways, Web UIs.
  • Key features like authentication, authorization, integration with other databases provided.

Akka HTTP

  • Based on Akka to provide asynchronous and non-blocking HTTP servers.
  • Supports streaming APIs with Akka streams and reactive streams.
  • Client-side API provides asynchronous, non-blocking, and streaming support.
  • Provides high-level and low-level routing.
  • Used primarily to add lightweight REST/HTTP endpoints to an application or build rich HTTP servers.

Lagom

  • Built on top of the Akka cluster and Play.
  • RPC style communication between microservices.
  • Integration with queueing mechanisms like Kafka.
  • Entities based on the model of Domain Driven Design.
  • ES/CQRS built-in.
  • Abstraction for service location to enable integration with Kubernetes, DNS, Zookeeper, etc.
  • The primary use case is to build microservices based systems based on the RPC style.

As you would notice in all of the above, the powerhouse is Akka. Let us quickly talk about Akka as well

Akka

  • A toolkit based on the actor model to simplify concurrency and improve resource usage.
  • Akka cluster includes sharding, CRDT, cluster wider singletons, routers, etc.
  • Akka streams provide streaming endpoints and are optimized to work with streaming data, based on the Reactive Streams.
  • Alpakka provides endpoints to integrate with a large number of external technologies.

If you are still unsure about why to use Akka and not stay with Spring, refer to this post.

Summary

Systems today need to be built as platforms. They would need to interact with other systems and expose endpoints which other systems would be able to consume and innovate on. They would need to support key features like asynchronous communication, non-blocking calls, optimal utilization of resources so as to stay resilient in a webscale world. Do not build systems today which would not follow the motivations of the reactive manifesto. 

Source: DZone

Leave a Reply

Your email address will not be published. Required fields are marked *