How to apply micro-service architecture to you application

Doga Budak
4 min readAug 27, 2022

--

Micro-service architecture, or simply micro-services, is a distinctive method of developing software systems that tries to focus on building single-function modules with well-defined interfaces and operations. You probably hear about it a lot these days, a lot company is using this kinda architecture and moving away from monolithic hells.

Today I will share one of the application that i was writing with the help of micro-services and share the thought processes i had, hoping that it would be really helpful to grasp the problem . I always think self learning starts with coding and practice so lets dive deep into the topic with real code examples.

What is the application ?

So to be honest that is the least important question but let’s start with it. I want you guys to be familiar with the application itself.

I called it piarcha ( don’t ask me why). An application for tourists, which helps people to get to know a city better by offering some small tours. A typical application like this would have a user management system with authorization and authentication, it would access to some certain resources from db through another service minimum. Of course you can add more use cases and more services for this service to run but lets get started with this easy small application.

Before I forget, I will be writing this application in react-native at the front end and with typescript & rust lang at the backend. This is an intentional choice to show you we can spice things up with different languages.

The front end project that I am talking about is this one here

https://github.com/dogabudak/piarcha_react

Name your repositories accordingly

Lets start with the obvious one, you should name your project, maybe a code name or something like that, but then you have to apply to all of your projects. With this approach you will know which project in your github, related to which project.

But actually another approach is also possible here, Monorepos. I am personally not a huge fan of it but it is still worth mentioning it. It is possible to keep your app under one repository and with the help of docker or some start scripts, you can separate the applications into tiny services. It is actually a nice article topic but I will get to that later.

Create separate services for each use case

Now here comes the question, how can you separate your projects ? There will be a lot more conjunction than you think but the easiest way to separate is to separate it depending on the use cases.

In my little application I made so far 3 services. One is for user services, one for Authorization, an authentication, and providing business information such as location data. As you can see each one of these services are completely independent as well and failure of one does not effect the other one. Lets say our user service has failed and not starting for some reason, customers will still be able to walk around and make their visits.

Actually when I first started, i created more services than I needed to. I created for for user registration, and another one for user information update. But the objects and databases that they are using are practically the same. Then i thought, why i don’t merge these projects together. It literally made my development and maintenance easier, so avoid over separating.

Crete independent services

A micro-service architecture is not a pure micro-service if you don’t have completely independent services. By the design your architecture should consist completely independent services from each other. I find this approach a bit unrealistic, since generally it’s not so possible to apply this principle. But you should be aware of this theory. What I try to apply is to use the same database and maybe same types throughout the application. This way, i can keep things consistent. Here you can see the common types that I created for my application. The good thing is that you can even use npm-registery for using these types.

https://github.com/dogabudak/piarch-a-interfaces

A Simple design of the system

How should your services communicate to each other

In applications like mine, it is generally a good idea to have token when you communicate with other services. The token that you are using can keep user information and help you to identify the users authority to make certain operations.

Communication model is completely unrelated to the solution here, either you are using http layer or you communicate with tcp sockets, you can always include a header to your requests and this header can consist the token.

All the projects I make are under here. If you have any extra questions feel free to ask them to me. If you want to contribute to this small micro-service architecture project, feel free !

--

--