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

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.

主站蜘蛛池模板: 马尔康县| 神农架林区| 阿拉善盟| 凤凰县| 蓬莱市| 孙吴县| 仁布县| 平阳县| 伊川县| 丰顺县| 镇坪县| 抚顺市| 东乡县| 星座| 志丹县| 瓦房店市| 鸡泽县| 龙陵县| 洱源县| 常宁市| 突泉县| 德钦县| 宁阳县| 偏关县| 手游| 南平市| 大兴区| 乡宁县| 肇东市| 长春市| 永州市| 东兰县| 新竹县| 安泽县| 双江| 灌南县| 望江县| 长垣县| 泌阳县| 乌鲁木齐市| 台东市|