Best practices for Microservices / Web Application Developers.

Gawesh Prabhashwara
4 min readJul 14, 2022

The best practices for microservices architecture that we must adhere to in our project will be covered in this post. Understanding these procedures will enable you to steer clear of common errors. Let’s look at them one by one. For more information on the Microservice Architecture, please see my previous articles.

1 . Design should be the Domain-Driven Design.

Before beginning a project with a microservices architecture, we need think about it from scratch, consider our domain, and determine whether each service can function independently. Additionally, while moving an existing program to microservices, it is important to reconsider how the various domains of the application should be separated from one another. It does not imply that we must start from scratch or completely recode the application. Simply take some time to review our project services. If a module is included in another module but the two modules are unrelated, we can build them as independent services. We don’t need to modify or replace the code in this instance. At the same time, the Domain requires our attention. A microservices architecture project does not consist of two services when there is room for more. As a result, we should allow our project extra time to be evaluated. Otherwise, it will become more complicated and lose some of the features of the microservices design.

2. Hardcoded Value.

The complexity of an application is distributed over a number of services when we talk about microservices. We need to have communication across many services running on various machines in order to implement a single business requirement. Let’s say we link services A and B using the hardcoded hostname and URL, and the application functions as intended. However, if the network team were to change the URL or hostname one day, we would be in grave danger since our program would cease to function and we would have to deploy it again using a new URL or hostname. It is obvious that this is not a recommended practice. Therefore, we must use the facilities of the services discovery method rather than hardcoding. Service discovery is the process of automatically detecting devices and services on a network.

3. Logging.

Logging is a crucial component of the microservices architecture since it enables us to find application failures. Both too many and no logs are bad practices. Everywhere the process is started, we need to keep logs. However, there shouldn’t be any logs or logs everywhere.

4. Versioning Microservices.

When two services are running in separate versions, versioning is another crucial component of microservices that keeps our program from failing. Symmetric versioning is the ideal versioning method. The three components of the semantic version are major, minor, and patch, respectively. The components of the semantic versioning concept are shown in the graphic below.

5. Handling Authorization and Authentication.

The recommended approach for creating an application using a microservice architecture is to validate the user at each service. For illustration, consider the vehicle rental application. When a customer is assigned a vehicle, it may call for three separate services, all of which must validate the consumer.

6. Dependency.

We should not rely on anything. Assume we have three services, A, B, and C, each of which depends on the other. In this situation, it is more difficult for us to deploy each server independently. Additionally, it is absurd for a microservice, therefore every service must be independent of the others. Any service can be deployed at any time without causing a conflict or harming others.

7. Tolerance (Executable Contracts).

Make the servers user-friendly. If we use the monolithic application, we create a user-friendly application because the same server also has users, and it is our duty to create services that are simple to use. On the other side, when there are more than two or three services in a microservice design, the user cannot effectively use it if one of them fails or takes a long time to reply. Therefore, in order to address the aforementioned issues, we currently require an appropriate management system.

8. Documentation.

Whether we like it or not, recording our effort is a crucial component. Only in this way can future audiences of our work benefit from it. A technical document needs to be written. One of the best tools for writing technical texts is the swagger. We have the ability to write in technical terms, and our arrogance turns those terms into technical documentation.

Reference :-

Krishantha Dinesh, Best practices for Microservices / Web Application Developers Dec 29, 2016,

--

--