Let's create microservices system from scratch - series intro
Tags: microservices, architecture, beginners
Published: 2021-01-12 17:33:13

# Intro

Well, the title seems like a bold statement, so let's clarify what I mean by *microservices system*. I **do not** mean a framework of any kind to be used in production, only a project to learn about the challenges of the microservices architecture and how it *might* work under the hood.

I do not intend this series to be step by step guide since it would probably be at least 100 articles long by the end. I will, instead, try to write about design choices, how to write some of the mechanisms and highlight some interesting problems (from full stack developer point of view) I stumble upon along the way.  

# What are we building

First of all, what type of system are we aiming for ? This will determine what kind of services we will need, as well as non-functional requirements of the system.

Recently I've been playing Middle-earth: Shadow of War and I thought to myself: why not create management application for the Saurons army ? Hence the idea for *The One System to Rule Them All* (*The One* for short). Then I decided to turn it into a learning experience and so I will not limit myself to Java and Angular which I know, but will also try to learn other languages along the way. 

# Technology stack

The technologies I intend to use and learn at least the basics of, are:

1. For services:
 * Java ([Zulu](https://www.azul.com/downloads/zulu-community/?package=jdk)) and [Spring BOOT](https://spring.io/projects/spring-boot) (there is a limit to what I can write from scratch ;))
 * [Haskell](https://www.haskell.org/) - because I never used Functional Language before
 * [Python](https://www.python.org/) - because it's widely popular
 * [GoLang](https://golang.org/) - because why not
2. For frontend:
 * [Angular](https://angular.io/) for the UI
 * Java ([Zulu](https://www.azul.com/downloads/zulu-community/?package=jdk)) and [Spring BOOT](https://spring.io/projects/spring-boot) for the server side
3. For deployment:
 * [Docker](https://www.docker.com/) and Docker-compose
4. Architecture pattern:
 * [Microservices](https://en.wikipedia.org/wiki/Microservices) for the services
 * [SPA](https://en.wikipedia.org/wiki/Single-page_application) for frontend

Now, having decided that for a start, are we going to use libraries such as Netflix Hystrix, Ribbon ? Are we going to use RabbitMQ ? Well, **no**. Since this is a learning experience, we will try to implement it ourselves. It may not end up being the best code ever, but it will give us overview of how this libraries are implemented which in turn, can help us debug or implement other solutions better in the professional life.

# The architecture (v0.0.1)

Ok, having more or less decided on the tech stack, we now need to design the actual architecture. *The One* is basically a resources management system where the resources range from uruks through the outposts up to the food chains and weapon storages. 

Every management system needs to have some kind of users database to allow access control, authentication and authorization services and UI app to allow user friendly access. But since the chosen architecture is microservices, we cannot simply write one Spring BOOT app and be done with it, we also need:
* [API Gateway](https://microservices.io/patterns/apigateway.html) to connect to different services
* [Service Discovery](https://microservices.io/patterns/server-side-discovery.html) to allow us dynamically starting and stopping services
* Logger Service to aggregate logs from every service
* Service monitoring 
* And a few other things

The basic diagram will look like this (I omitted some things in order to make it a little smaller):

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tj2vm1d3aj5h4773ybbj.png)

It may seem like it won't be much work - and normally in a company it probably wouldn't - but we are going to build this from scratch, therefore, the first milestone will be:
1. Create API Gateway Service, that proxies requests to User Service, to address obtained from Service Discovery. 
2. User Service and API Gateway will wait for Service Discovery startup before starting themselves.
3. After startup, User Service will register itself with Service Discovery, passing the IP and PORT on which it's available.
4. There will be script to build and run everything either locally or using docker.

# Summary
I think the milestone we've set for ourselves is relatively easy but will be a bit challenging to implement from scratch :) See you in the [next part](https://dev.to/digitalcrafting/let-s-create-microservices-system-from-scratch-part-2-5eoh).

[Here's the repo for this project.](https://github.com/DigitalCrafting/microservices-the-one-project) Feel free to copy it and tinker around :)