Go microservice: API gateways pattern

The purpose of this article helps you to understand how to develop basic microservices by using API gateways pattern.

1. Requirements:

  • Microservice:

A microservice application is a collection of autonomous services, each of which does one thing well, that work together to perform more intricate operations. Instead of a single complex system, you build and manage a suite of relatively simple services that might interact in complex ways. These services collaborate with each other through technology-agnostic messaging protocols, either point-to-point or asynchronously.

gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.

  • How many microservices patterns do we have?

https://medium.com/@madhukaudantha/microservice-architecture-and-design-patterns-for-microservices-e0e5013fd58a

Redis is an in-memory data structure project implementing a distributed, in-memory key-value database with optional durability.

2. What we build:

Postman

3. System architecture:

3.2. Our system architecture:

4. Happy scenario:

  • user registers an account and we save the user information to the local database.
  • user logins and we return a Jwt token.
  • user get their profile by sending the Jwt token.

5. Our microservices:

user.proto will have 2 methods: CreateUser and ReadUser which are to help to register/log in.

user.proto
  • Front controller:

This helps handle all requests, consume the message from microservice and return for frontend.

  • Entry cache service:

The basic concept of entry cache service is to get the user from Redis if any. Otherwise, we will get information from the local database.

user.go
  • Entry store service:

The purpose of this microservice is to connect to the local database.

user_dao.go

7. Conclusion:

I’m a peaceful person who wants to make friend with people around the world.