Taxonomy Icon

Java

Chirper is a Reactive Platform sample, containing four microservices demonstrating a simple microblogging site. It makes use of the Playand Lagom frameworks and the Akka toolkit – three of the key open source constituents of the Reactive Platform. In a previous blog post, we showed you how to run the sample on the IBM Kubernetes Service (IKS), part of the IBM Cloud. We built the application using sbt, pushed the four Docker images to the IBM Cloud Container Registry, and deployed the microservices to Kubernetes using the kubectl command line tool and Lightbend Orchestration’s rp command. We are now going to show you how to deploy Chirper to IBM Cloud Private. We’ll use the example Helm chart in the IBM Helm chart repository. In case you were wondering, IBM Cloud Private provides the benefits of the public cloud from the safety of your own data center. Key to this example are its integrated Kubernetes, Docker registry, and catalog of Helm chart repositories through a web front end.

What is Chirper?

The Chirper microblogging sample has four microservices which come together into an application that lets you: create a user, “chirp” short microblogs by that user, “friend” another user, follow the microblogs of one or more friends, and display them in a feed.

Actors, Akka, Play, and Lagom

Akka is a modern realization of Carl Hewitt’s Actor Model on the Java Virtual Machine.

The actor model provides an abstraction that allows you to think about your code in terms of communication, not unlike people in a large organization. The basic characteristic of actors is that they model the world as stateful entities communicating with each other by explicit message passing. (Akka introduction)

Building on this, Akka provides:

  • Multi-threaded behavior without the use of low-level concurrency constructs like atomics or locks. You do not even need to think about memory visibility issues.
  • Transparent remote communication between systems and their components. You do not need to write or maintain difficult networking code.
  • A clustered, high-availability architecture that is elastic, scales in or out, on demand.

Built on Akka, the Play web framework is stateless, asynchronous and non-blocking. This enables it to deliver a high degree of responsiveness, elasticity and resilience, empowering developers to build highly scalable, lightening fast applications.

Fundamentally, the Chirper sample is a Lagom framework sample – A sample consisting of reactive microservices acting as a system, so that your microservices are “elastic and resilient from within.”

Building Reactive Systems can be hard, but Lagom abstracts the complexities away. Akka and Play do the heavy lifting so you can focus on a simpler event-driven programming model on top, while benefitting from a message-driven system under the hood. (Lagom framework)

Lagom helps you build microservices as systems, and in the Chirper sample there are four services in our system: activity-stream, chirp, friend and front-end.

  • The activity-stream microservice enables the user to get the feed of all of the “chirps” relevant to them. These include their own posts as well as their friends’.
  • The front-end microservice generates the web user interface for the sample application providing the access point for the other three microservices.
  • The chirp microservice adds the ability to post “chirps” and retrieve historical “chirps.” These historical chirps are then used by the activity-stream microservice to populate the user’s feed.
  • The friend microservice enables the creation of new users. Users can log in and add friends’ friends to follow.

Two of the microservices, Chirp and Friend, are implemented as Akka Clusters with three cluster members each. These clusters are one of the key components in the Akka toolkit. Actors running within the application can be scheduled across any of the cluster members and in this way the work is load balanced. So, by implementing these services as Akka clusters, their actors will be distributed across machines – load-balanced for resiliency, and the number of cluster members can be scaled up and down as needed – for elasiticity.

Deployed alongside the application, is a Cassandra database to store the user data and any “chirps” created by a user. ICP’s built-in Ingress service is configured to route inbound requests from Chirper’s web interface to the various endpoints of the other mircoservices.

In order to achieve this deployment and configuration to ICP, in one neat package we’re using a Helm chart. Helm is a package manager for Kubernetes, and it uses a packaging format called Helm charts, which help to define, install, and upgrade Kubernetes applications.

In contrast to how we deployed Chirper to IKS, we have put together a Helm chart to pull all the pieces together. This is Apache licensed and is in our ICP Helm Chart Github repository. You can install all the pieces of the application by running the Helm chart from the ICP catalog web UI.

How to deploy the sample application

To deploy this sample application, you will first need access to an ICP cluster. The sample application can then be deployed through the ICP catalog, but before installing you need to have a namespace that you can access. See the ICP documentation on how to do this. To install the chart with the release name my-release:

  1. Search the catalog for ibm-reactive-platform-lagom-sample.

  2. Select Configure.

  3. Enter the release name. (Note: This needs to be a unique name.)

  4. Select the target namespace. (Note: Only one instance of this sample application can be deployed to each namespace.)

  5. Accept the license agreement.

  6. Enter the hostname used to access the Chirper sample application with Kubernetes Ingress (for example, chirper.<icp proxy node address>.nip.io).

  7. Select Install.

Note: NIP.IO is a domain name that provides wildcard DNS (Domain Name System) for any IP address. These domains can access virtual hosts on your development web server from devices on your local network without the need for any installations or configuration.

You will need to wait until the sample application has been fully deployed before trying to access/use it. You can view its progress from the release review page, via the ICP UI, which is accessible straight after the deployment (or can be found under “Helm Releases” and the name of your release). Once deployed, you can go to the URL entered as the hostname above to see the Chirper UI and use the sample application.

If you do not want to use the ICP catalog to deploy the helm chart to ICP and instead want to use the command line, the instructions to achieve this can be found in the README.md file in the chart repository.

Where to go from here

This is a relatively small example of a reactive application that demonstrates Akka clustering and other reactive principles. If you would like to view the source code you can see the SBT sample and the Maven sample. Or, if you want guidance on developing a helm chart for your own reactive application, you can see ours.

Start building with three simple steps

  1. Install IBM Cloud Private Catalog.
  2. Search for Reactive.
  3. Select IBM Reactive Platform Lagom sample.