0.2.38 • Published 9 months ago

@turnly/grpc v0.2.38

Weekly downloads
-
License
UNLICENSED
Repository
github
Last release
9 months ago

gRPC — Inter-services communication

This shared module facilitates inter-services communication through the RPC protocol.

Installation

pnpm @turnly/grpc

Usage

Consumer (client)

This is an example of how to consume Tickets data via RPC using a consumer.

import { Consumers } from '@turnly/grpc'

const Tickets = new Consumers.QueuingSystem.Tickets({
  /**
   * This param is optional, if we find GRPC_CONSUMER_ADDRESS in your .env we will ignore it.
   */
  address: '0.0.0.0:50052',
})

Tickets.getOne({ id: 'ticket_eHgxSkoq2msf' }).then(console.log)
Server producer

This is an example of how to set up an RPC server to define the services of a pre-built proto.

This example assumes that you've already created a my-service.proto and want to create the implementation.

import { Producers } from '@turnly/grpc'
import { TicketsModule } from 'tickets/tickets.module'

const services = [
  {
    definition: Producers.QueuingSystem.TicketsService,
    implementation: TicketsModule.getServer(),
  },
]

const server = new Producers.Server({ port: 50052, services })

server.setup() // gRPC server started on port 50052

Why use gRPC?

Communication between microservices must be efficient and robust. With lots of small services interacting to complete a single business activity, this can be a challenge.

There are two types of communication between services; Synchronous and Asynchronous.

Asynchronous communication in microservices will be achieved through the messaging brokers like Apache Kafka.

Most likely in a distributed system you need to communicate with some of your neighboring services at the request of a client, this type of case is where you will need to communicate directly with a service synchronously and wait for its response.

With that said, you will understand why having synchronous communication is crucial in a service-oriented architecture and for this we chose RPC because of the following:

  • Building low latency and highly scalable microservice call graphs.
  • gRPC uses Protocol Buffers by default, which provide better performance when compared to JSON.
  • Ability to auto-generate client stubs in several languages, which reduces the responsibility of building and maintaining client libraries.
  • gRPC communication happens over HTTP/2. HTTP/2 enables more efficient use of network resources and reduces latency by using header field compression and allowing concurrent exchange in the same connection.

In addition to the great advantages of RPC, we use the Circuit Breaker pattern in our consumers (clients) to mitigate the minimal temporal coupling of our services and prevent cascading failure propagation.

0.1.58

10 months ago

0.1.59

10 months ago

0.2.27

9 months ago

0.2.26

9 months ago

0.2.25

10 months ago

0.2.24

10 months ago

0.2.23

10 months ago

0.2.22

10 months ago

0.2.21

10 months ago

0.2.20

10 months ago

0.2.19

10 months ago

0.2.18

10 months ago

0.1.74

10 months ago

0.1.70

10 months ago

0.1.71

10 months ago

0.1.72

10 months ago

0.1.73

10 months ago

0.2.30

9 months ago

0.1.63

10 months ago

0.1.64

10 months ago

0.1.65

10 months ago

0.1.66

10 months ago

0.1.67

10 months ago

0.1.68

10 months ago

0.1.69

10 months ago

0.2.38

9 months ago

0.2.37

9 months ago

0.2.36

9 months ago

0.2.35

9 months ago

0.2.34

9 months ago

0.2.33

9 months ago

0.1.60

10 months ago

0.2.32

9 months ago

0.1.61

10 months ago

0.2.31

9 months ago

0.1.62

10 months ago

0.2.29

9 months ago

0.2.28

9 months ago

0.1.52

12 months ago

0.1.53

12 months ago

0.1.54

12 months ago

0.1.55

11 months ago

0.1.56

11 months ago

0.1.57

11 months ago

0.1.50

12 months ago

0.1.51

12 months ago

0.1.49

12 months ago

0.1.41

12 months ago

0.1.42

12 months ago

0.1.43

12 months ago

0.1.44

12 months ago

0.1.45

12 months ago

0.1.46

12 months ago

0.1.47

12 months ago

0.1.48

12 months ago

0.1.40

12 months ago

0.1.38

12 months ago

0.1.39

12 months ago

0.1.30

1 year ago

0.1.31

1 year ago

0.1.32

1 year ago

0.1.33

12 months ago

0.1.34

12 months ago

0.1.35

12 months ago

0.1.36

12 months ago

0.1.37

12 months ago

0.1.27

1 year ago

0.1.28

1 year ago

0.1.29

1 year ago

0.1.20

1 year ago

0.1.21

1 year ago

0.1.23

1 year ago

0.1.24

1 year ago

0.1.25

1 year ago

0.1.26

1 year ago

0.1.19

1 year ago

0.1.18

1 year ago

0.1.17

1 year ago

0.1.16

1 year ago

0.1.15

1 year ago

0.1.14

1 year ago

0.1.12

1 year ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago