In “A Self-Evolved Microservice Framework in Go”, I described a framework that can evolve itself. It has two pieces, one is the lightweight framework, the other is the pluggable third-party components. You can call this architecture “small framework, big library”. In this article, I will talk about how to create pluggable third-party components. The followings are what you need to consider.

  • External interfaces of third-party libraries
  • The internal structure of the third-party library
  • How to handle configuration parameters
  • How to expand third-party libraries

We use logs as an example to show how to create third-party libraries, I named it “glogger”

Last year, I created a framework for Microservice, which is a powerful one but a little heavy. I wrote a series of articles talking about it, please read “Go Microservice with Clean Architecture” for detail. I also pointed out some drawbacks in the design and expected to come back and fix those later. I finally got time to improve it. The result exceeds my expectation.

The changes I made are relatively small, but the improvement is huge. The main project structure and layout is still intact, most of what I wrote in those articles are still held, but it fixed…

Have you ever encountered such a framework, it is very simple and lightweight, easy to use, but when your project becomes complex, it can evolve into a powerful heavyweight framework, without the need to rewrite the entire project? I have never seen it before.

Let us first look at the life cycle of a project. Usually, when a new project starts, we don’t know how long it will last, so we want it to be as simple as possible. Most projects die in a short period, so they don’t need a complicated framework. However, some of them have hit the…

In my article “A Non-Intrusive Transaction Management Lib in Go — How to Use It”, I described how to use the transaction lib. In this article, I will focus on the Lib itself. Some of you may have read “Go Microservice with Clean Architecture: Transaction Support”, which described the old version of the transaction management system. There will be some overlap between that article and this one. Since most people probably haven’t read that one or forgot what it is about, so it is better to start from scratch (Assume that you haven’t read the previous one).

A good transaction…

In the article, “Go Microservice with Clean Architecture: Transaction Support”, I talked about how to implement a non-intrusive transaction management system in the Clean Architecture. It allows you separating transaction code with business logic and not thinking about the transaction when writing business logic. But it has some drawbacks. First, it is embedded in the framework, so it can’t be used separately. Second, even though it is non-intrusive to the business logic, it is intrusive to the framework. I need to change all layers of the Clean Architecture framework to get it to work and it is not very easy…

Service Resilience means that when the service’s operating environment has problems, such as network failure, service overload or some microservice downtime, the program can still provide some level of the services. Then, we say that the service is resilient. It is a very important part of Microservices and is widely discussed. It improves the quality of a service by improving the resilience of services to compensate for environmental deficiencies.

Service Resilience Improves the reliability of services through the following technologies:

  • Timeout
  • Retry
  • Rate Limiting
  • Circuit Breaker
  • Fault Injection
  • Bulkhead

Code Implementation:

Service resilience can be achieved in different ways, let’s implement it…

In Microservice architecture, the calling chain is long and complex, to understand each component and the performance of it, you need something called distributed tracing. The idea is simple, you generate a unique ID at the beginning of each request, and carry it along the whole calling chain. The ID is called Correlation ID¹ and you can use it to trace the performance of the entire request. There are two problems need to be solved. …

In Clean Architecture, each layer of the application ( use case, data service and domain model) only depends on interface of other layers instead of concrete types. At run-time, the the application container¹ is responsible for creating concrete types and inject them into each function, the technology it used is called Dependency Injection². The following is the requirements.

Requirements for dependency relationship on container:

  1. The container package is the only package that depends on concrete types and many outside libraries because it needs to create concrete types. All other packages in the application mostly depend only on interfaces.
  2. The outside…

One philosophy of Clean Architecture is to isolate framework for the application, so the framework won’t take over your application and you decide when and where to use them. In this application, I purposely not using any libraries at the beginning so I can have a better control on the project structure. Only after the whole application structure is laid out, I will consider replacing some components of the application with libraries. This way, the impact of introducing a framework or a library is isolated by the right dependency. …

Good logging can provide informative log data and make it easy to find problems when doing debugging, thus greatly improve coding efficiency. The more automated information provided by the logger the better it is, also the log information needs to be presented in a concise way, so it is easy to find the important data (Please note, there is a new version of it, which I extracted the code out to create a third-party library, which can be used outside of the framework. Please check out “How to write a pluggable third-party component in Go”)

Logging Requirement:

  1. Be able to switch to…

Jin Feng

Writing applications in Java and Go. Recent interests including application design and Microservice.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store