Connection pool

We are planning to build 10 microservcie in GO and we are using GO KIT and GORM. How connection pool will be maintained across the 10 different services or is it better to build connection pool per service ?Do you need to have one connection pool for all service or connection pool by service. Do you have anything in GO-KIT?

2 Likes

I haven’t used gokit or form so far, but, as microservices usually are distinct programs, sometimes even on distinct containers/physical machines, you can’t do any connection sharing between them and each service needs its own connection pool.

2 Likes

Ok. How can I do connection pool within service?

2 Likes

I suppose you are asking for database connections, if it is, gorm db is a connection pool.

// SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
db.DB().SetMaxIdleConns(10)

// SetMaxOpenConns sets the maximum number of open connections to the database.
db.DB().SetMaxOpenConns(100)

// SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
db.DB().SetConnMaxLifetime(time.Hour)
2 Likes

The intention of microservices is to have isolated independent services. Each might provide a small number of services for example REST services. If you do not run them independently you cannot technically share the connection pool.

If they shared a resource, you could encounter cascading failures. One service fails and impact the other services.

2 Likes

Microservice Architecture: Transport
EX1: REST - share your models between services. go package style.

+--------------+                   +--------------+
|              +------------------->              |
|  Service-A   |      REST         |  Service-B   |
|              +<------------------+              |
+--------+-----+                   +--------------+
     |				
+----+----+				
|Service A|				
|   DB    |				
+---------+

EX2: GRPC

       +---------+Share A .proto+-----------+
       |                                    |
       |                                    |
       |                                    |
+------v-------+                   +--------v-----+
|              +------------------->              |
|  Service-A   |      GRPC         |  Service-B   |
|              +<------------------+              |
+--------+-----+                   +--------------+
     |
+----+----+
|Service A|
|   DB    |
|         |
+---------+

EX3 : Message Bus. useful in special conditions like compulsory queuing.

+--------------+                   +--------------+
|              |                   |              |
|  Service-A   |                   |  Service-B   |
|              |                   |              |
+---+-----^-+--+                   +--+-----------+
    |     | |                         |                   +------------+
 +--+--+  | |                         |                   |            |
 |A DB |  | |                         |                   |  Service-X |
 +-----+  +-v-------------------------v----+-------------->            |
          |             NATS               |              +-------+----+
          +--------------------------------+                      |
                                                               +--+---+
                                                               | X DB |
                                                               +------+
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.