9 Basic (and Crucial) Tips for Microservices Developers by@omelnic

9 Basic (and Crucial) Tips for Microservices Developers

image
Oleg Melnic HackerNoon profile picture

Oleg Melnic

Technical Lead in the company Proxify

If you’re going to work on microservices projects, you need to learn some basic tips. I’ve provided them below, so get acquainted with them and perform to the best of your ability!

1) Use a Domain-Driven Design

To provide the best performances, developers design scopes for every microservice. However, some of the represented elements aren’t necessary for a good performance. That is why we consider it to be a good idea to get rid of useless elements represented in scope. The best option for microservices developers is to use domain-driven designs. So check this out to be sure that your microservice works with the use of the domain-driven design. In some cases, it’s not relevant to change the whole range of elements but consider that the scope mentioned above should be well-defined. We don’t recommend using multiple modules provided from different domains. This method isn’t what microservices require.

2) Avoid hardcoding

To better understand this recommendation, we need to get familiar with one simple example. Imagine service No1 requesting service No2. If the second one is hardcoded in the first one, some difficulties may occur with the necessity to locate a second one. This happens when the second service’s hostname or IP address is changed. The same concept works for foreign services’ addresses. They will not be simply located. In such cases, service discovery tools must be implemented.

3) Maintain Logging

Somebody doesn’t understand why having too many logs might be the same bad as keeping no logs.

Let’s figure this out.

We will consider the same services as in the previous tip but let’s add one more – service No3. The first requests the second, and the second one does the same to the third. Due to different reasons, the third service might fail. In such cases, the request goes back to the second one, which does the same thing as the third one – it just reports the error to the previous - No1.

The error isn’t solved this way, moreover, it’s logged in to 3 independent places. In addition to that, a single system may feature a higher number of such places. The solution, on such occasions, is quite simple – just avoid simultaneous logging into multiple services. To get more details about the fail, we recommend using a Correlation ID.

If you want to understand what this term means, the explanation isn’t so complicated. In a nutshell, it's an identifier value that is created at random to be further pinned to the following requests and responses.

The services just pass this identifier to the following services that are located in the general architecture. This is the most convenient way to find the part of the microservice where the fail actually happened.

4) Versioning

Even if the service is effective, it must be updated and modified due to the current needs. The modification of the service brings us a few more versions of it. Consequently, in some cases, the whole architecture might be broken down by one of the modifications. That is why you need to be keen on versioning in order to fail and create modifications that aren’t interoperable for your specific system.

In this paragraph, we’d like to focus on Semantic Versioning and its benefits for microservice performance. In Semantic Versioning, the major modification is defined under the X letter, the minor – under the Y letter, and a patch is denoted by the Z letter.

image

The picture above represents how the basic form of Semantic Versioning should look like. Don’t forget about the following key features of Semantic Versioning: The initial version is 0.1.0, due to the reason that there are no preceding bug fixes. The range of features is similar to the one represented in the project’s draft. Everything that is lower than 1.0.0 can’t be considered a stable version – these are just developing modifications.

We also need to understand how the “force upgrade” concept works because this is what we should concentrate on when developing further modifications. We are going to figure this out with the following example. Imagine, we have 2 services. The first one calls the second one, in addition to that, the second service requires modification. You take the necessary steps to update the database. Due to this, the request is changed, which may break the first service. Now we need to learn how to solve such problems. Versioning is just what you need to get rid of difficulties in such cases.

This works in the following way: you increment the major version number and deploy it as a separate service, or, in simple words, you create 2 versions of the second service. Don’t forget to remind your customers about the necessity to update the service during the specified period of time. If they follow your instructions, you will have the possibility to shut down the older modification and allow the traffic to migrate to the new version.

This is not the only method that might be implemented to help you solve the problem. In a second way, customers need to update the services as well but you don’t need to set special terms – increasing the number of instances for the newer version is enough. This method is called Elastic because you don’t need to limit customers with specific dates

5) Authentication and Authorization

The architecture of a microservice is designed in a way that may make a request go through multiple services. It takes a longer time, which isn’t quite convenient for your users.

Everything depends on the number of services trying to validate the user. If there are 4 such services, the authorization may go 4 times longer. For instance, one service takes 30 milliseconds, while 4 services will take 120 milliseconds.

If you don’t want your customers to face that, we recommend using a separate identity validation service. With it, you’ll be able to direct all the requests in a single direction. If the validation is successful, you can direct them to the rest of the path. This is referred to as “Force Forwarding”.

6) Dependency

One of the most important features to be taken into developers’ consideration is that microservices should be isolated and independent. If services are dependent on each other, it may cause a number of difficulties. For instance, you won’t be able to deploy one service in case the deploying process of another one is failed. That drives us to an obvious conclusion – services must be independent of each other in order to provide us with the possibility of unexpected issues caused by services dependencies.

7) Make Executable Contracts

This is relevant for the processes when this type of agreement is signed by two parties. It’s impossible to break executable contracts. This is important because they may contain different scripts, requests, etc. Even if some tests, included in executable contracts, are failed, you will have the possibility to fix the issues.

8) Fault Tolerance

Fault tolerance is one more important feature for any microservice system as it determines the capability of the whole architecture. The thing is that good fault tolerance excludes the risk of the system breakdown in cases errors occur to separate elements. Establishing good fault tolerance is the best way to improve efficiency. Let’s take a look at a robust tolerance mechanism. In a nutshell, it needs to ensure a faster time of failure in order to prevent queues waiting for the necessary responses from the services.

9) Documentation

If you want your users to be aware of all your steps related to improving the service’s performance, you need to document everything. Swagger is a good service to help write technical documentation. It makes everything clear and understandable, and even complicated technical terms become not as difficult with the help of Swagger.

Comments

Signup or Login to Join the Discussion

Tags

Related Stories