Project Link: https://github.com/Joker666/microservice-demo/
If you have not been living under the rock for a while, microservice is the defacto architecture to make large scale applications these days. A lot of companies have moved from monolithic architecture to microservice-based architecture like Uber, Netflix, Etsy, and so on. Companies adopt this structure as it simplifies their development and reduces complexity.
This is a 6 part tutorial where we will build a complete microservices-based application from scratch. You can see what has been built already in the project link.
I have been writing microservices for a while. But I remember having little to no resource on the web for how to stick all the different parts together. I had to struggle a lot and find solutions with trial and error. It was a daunting experience. I wish the reduce some pain for the readers of this blog.
This is going to be a multipart series where I structure each article with specific technology and different service. This is going to be an introductory article that will demonstrate what we are going to build, the required tools and knowledge, and how to set up the environment for you to get started.
I won’t go in-depth about what is a microservice and how big should it be. It is an organizational choice to create small/large services. We will architect the services with different programming languages for demonstration, note that it is not required in practice.
We are going to build the world’s simplest task management software. A user can register, create projects/tags, add tasks to the projects and tag the tasks into categories. So we have divided the responsibilities into 3 services. We are also going to make an API Gateway service that routes outside API calls to microservices.
╔═════════════════╦═════════════════╦══════════════════════════════╗ ║ Service ║ Technologies ║ Description ║ ╠═════════════════╬═════════════════╬══════════════════════════════╣ ║ User Service ║ NodeJS, MongoDB ║ Authentication service ║ ║ Project Service ║ Python, MySQL ║ Project/Tag creation service ║ ║ Task Service ║ Ruby, PosgreSQL ║ Task assignment service ║ ║ API Service ║ Go ║ API Gateway service ║ ╚═════════════════╩═════════════════╩══════════════════════════════╝
We are going to use some cloud-native tools to bootstrap our project. The most important being the choice of the transport layer. While JSON based APIs were used to communicate within the services, now RPC based frameworks are more popular. We are going to use GRPC. There are resources online why this is the better approach, I will link some below. The main ones being, reduced latency between service calls, and it is built on language-agnostic Protocol Buffers. The main tools are
We will also need different programming languages and platforms installed in the system for developing each service
The built application is tested Unix based environments, in windows, you can use wsl2 for running the services but that has not been tested yet.
Getting started on some of the tools can be daunting if you are not already familiar with it like protocol buffers and GRPC or docker. I encourage you to go through some online resources first and get a basic understanding of what these tools do. You do not have to be a veteran to get started, just basic knowledge would do. I plan to write more about these tools. If I do, I will backlink them here.
There are many ways you can write microservices. The approach I will take will be a simple approach for beginners. Generally, microservices are small pieces of a large software that is glued together and it makes the whole application at the end. The services when deployed either independently or in a cluster, usually communicate among them in a private network that cannot be intercepted from outside or even exposed to the public. There is usually an API Gateway that is written which sits as the router for public API calls that routes them to relevant service or services and returns the response.
There are many open-source API gateways, but here we will write our own since the added complexity of these API gateways are not suitable for beginners I believe. Also not all API gateways offer JSON to RPC transcoding so that it can accept HTTP 1.0 requests, our one will.
While not the main target, I plan to add more tools to the project and write about it. Tools for
which are the pillars of observability.
I will publish the next article, which gets started on building the first service with NodeJS and MongoDB very soon. Till then stay tuned.