A Simple Example of WebSocket based Microservice Architecure using Akka-HTTP in Scala

Table of contents
Reading Time: 2 minutes

In my previous blog, I explained how you can implement WebSocket server using Akka-HTTP. As you know,  Microservice architecture has become very popular in recent years. This architecture fits perfect
1) When you want to give support of your application for many platforms such as web, mobile etc.
2) When your application consists of multiple services such as order service, account service, payment service etc.

In this blog, I have explained a simple example of WebSocket based Microservice Architecture using Akka-HTTP in Scala. You will see how WebSocket based Microservices can communicate with each other in a application.


In this example, there are two sub modules Account for Account related services and Order for Order related services. There is one more sub module Api, which will forward coming requests to their corresponding services.

Let’s create build.sbt for this multi module project.

Screenshot from 2016-08-08 00-48-08.png

Now create routes and its handler for Account service:-

Screenshot from 2016-08-08 00-55-29.png

Create routes and handler for Order service:-

Screenshot from 2016-08-08 00-55-45.png

Create routes and handler for Api service:-

Screenshot from 2016-08-08 00-55-52.png

You can find complete code here.

To run this example:-

– Open 3 terminals
– Execute `sbt “project api” run` from first terminal.
– Execute `sbt “project account” run` from second terminal.
– Execute `sbt “project order” run` from third terminal.
– Download `Dark Websocket terminal` web socket client extension of google chrome


You can find complete detail here to use this project.


Written by 

Ayush is the Sr. Lead Consultant @ Knoldus Software LLP. In his 10 years of experience he has become a developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality.

1 thought on “A Simple Example of WebSocket based Microservice Architecure using Akka-HTTP in Scala1 min read

Comments are closed.