官术网_书友最值得收藏!

Microservices internals

To build proper microservices, there are several components we would need to consider. To understand the five components, let's discuss the main tasks a microservice is expected to undertake:

  • The microservice will need to be able to send and receive messages with other services and the outside world so that tasks can be carried out in harmony. The communication aspect of a microservice takes different forms. Restful APIs are very popular when interacting with the outside world, and message queues are very helpful when communicating with other services. There are other popular techniques that are also popular such as gRPC.
  • The microservice will need a configuration layer; this could be via environmental variables, a file or database. This configuration layer will tell the microservice how to operate. For example, let's assume that our service needs to listen on a TCP address and a port number to be able to receive messages; the TCP address and the port number will be part of the configuration that gets fed to our service when it starts up.
  • The microservice will need to log events that happen to it so that we can troubleshoot issues and understand behaviors. For example, if a communication issue occurs while sending a message to another service, we'll need the error to be logged somewhere in order for us to be able to identify the problem.
  • The microservice will need to be able to persist data by storing it in a database or other forms of data stores; we'll also need to be able to retrieve data at a later time. For example, in case of the MyEvents application, our microservices will need to store and retrieve data related to the users, the bookings, and the events.
  • Finally, there is the core, the most important piece of our microservice. The core is the code responsible for the task that our microservice is expected to do. For example, if our microservice is responsible for handling user bookings, then the microservice core is where we write the code that would perform the task of handling the user's bookings.

So, based on the previous five points, the building blocks of a microservice should look like this:

Building blocks of a microservice

Those building blocks provide a good foundation to build efficient microservices. The rules are not set in stone. You can make your microservice either simpler or more complex, depending on the application you are trying to build.

主站蜘蛛池模板: 扎鲁特旗| 阿城市| 外汇| 乌拉特中旗| 图木舒克市| 岳阳市| 河北区| 日土县| 彩票| 廊坊市| 商南县| 健康| 清镇市| 卢湾区| 合阳县| 富民县| 正蓝旗| 溧水县| 资兴市| 富民县| 鹤山市| 广东省| 中江县| 曲麻莱县| 九台市| 抚松县| 东乌珠穆沁旗| 黄平县| 荥经县| 万州区| 依安县| 垣曲县| 金门县| 霍城县| 亚东县| 瑞昌市| 西平县| 富平县| 孟州市| 花莲县| 镇赉县|