Microservice Patterns - 3.2.4 Interprocess communication in a microservice architecture - Using Service Discovery


Reference


in order for one service to invoke another service using RPI, it needs to know the network location of a service instance. => Service Discovery

Using service discovery
Instance IP may change, then Service client need a way to find instance

OVERVIEW OF SERVICE DISCOVERY
  • Its key component is a service registry, which is a database of the network locations of an application’s service instances
  • The service discovery mechanism updates the service registry when service instances start and stop.
  • When a client invokes a service, the service discovery mechanism queries the service registry to obtain a list of available service instances and routes the request to one of them.

APPLYING THE APPLICATION-LEVEL SERVICE DISCOVERY PATTERNS
  1. Service register when start (Self registration pattern, instance information may contain health check URL)
    (Pattern: Self registration A service instance registers itself with the service registry. See http://microservices.io/patterns/self-registration.html.)
  2. Client query service and send request with cache mechanism and load balance strategy such as round-robin or random 
    ( Pattern: Client-side discovery A service client retrieves the list of available service instances from the service registry and load balances across them. See http://microservices.io/patterns/clientside-discovery.html.)

Good and Bad
Good: Handle the scenarios, including legacy system can support this way
Bad: When using some tool such as supported by JVM or Spring, can't be supported in non-JVM environment

it’s usually better to use a service discovery mechanism that’s provided by the deployment infrastructure because of application later implementation limitation.

APPLYING THE PLATFORM-PROVIDED SERVICE DISCOVERY PATTERNS
Platform such as Docker and Kubernetes have a built-in service registry and service discovery mechanism. Ex. DNS, VIP

Good and bad
Good: No application code needed
Bad: Need deployed to Docker or Kubernates


Microservice Patterns - 3.2 Interprocess communication in a microservice architecture - Communicating using the synchronous Remote procedure invocation pattern



Reference

Remote procedure invocation
A client invokes a service using a synchronous, remote procedure invocation-based protocol, such as REST

Using REST
THE REST MATURITY MODEL
  • Level 0: No resource concept. Client invoke service by HTTP POST
  • Level 1: Support resource concept. Client invoke service by HTTP POST
  • Level 2: Support resource concept. Use HTTP verbs to perform actions. GET -> retrieve; POST -> create; PUT -> update.
  • Level 3: Support HATEOAS (Hypertext As The Engine Of Application State) principle. (www.infoq.com/news/2009/04/ hateoas-restful-api-advantages) (Hard to imagine it)

SPECIFYING REST APIS
  • must define your APIs using an interface definition language
  • The most popular REST IDL is the Open API Specification (Swagger)

THE CHALLENGE OF FETCHING MULTIPLE RESOURCES IN A SINGLE REQUEST
  • allow the client to retrieve related resources when it gets a resource.  Ex.  a client could retrieve an Order and its Consumer using GET /orders/order-id-1345?expand=consumer
  • GraphQL (http://graphql.org) and Netflix Falcor (http://netflix.github.io/falcor/), which are designed to support efficient data fetching

THE CHALLENGE OF MAPPING OPERATIONS TO HTTP VERBS
there may be multiple ways to update an order
  • Use PUT
  • define a sub-resource for updating a particular aspect of a resource
  • Ex.  POST /orders/ {orderId}/cancel
  • Ex.  POST /orders/{orderId}/ revise
  • gPRC

Using gRPC
  • is a binary message-based protocol
  • define your gRPC APIs using a Protocol Buffers-based IDL
  • forced to take an API-first approach to service design
  • As well as supporting simple request/response RPC, gRPC support streaming RPC
  • uses Protocol Buffers as the message format

Handling partial failure using the Circuit breaker pattern
Pattern: Circuit breaker
An RPI proxy that immediately rejects invocations for a timeout period after the number of consecutive failures exceeds a specified threshold

DEVELOPING ROBUST RPI PROXIES
  • Network timeouts:  Never block indefinitely and always use timeouts when waiting for a response
  • Limiting the number of outstanding requests from a client to a service
  • Circuit breaker pattern: if the error rate exceeds some threshold, trip the circuit breaker so that further attempts fail immediately
  • Reference Implementation:   Netflix Hystrix (https://github.com/Netflix/Hystrix)

RECOVERING FROM AN UNAVAILABLE SERVICE
  • simply return an error to its client
  • returning a fallback value, such as either a default value or a cached response, may make sense


Microservice Patterns - 3.1 Interprocess communication in a microservice architecture - Overview of interprocess communication in a microservice architecture


Reference  

Overview of interprocess communication in a microservice architecture
Interaction styles
Dimension - 1
  • One-to-one—Each client request is processed by exactly one service
    • Request/response: client send request and wait for response
    • Asynchronous request/response: client send request to service without waiting, service will response later
    • One-way notifications: client send notification to service
  • One-to-many—Each request is processed by multiple services
Dimension - 2
  • Synchronous—The client expects a timely response from the service and might even block while it waits.
  • Asynchronous—The client doesn’t block, and the response, if any, isn’t necessarily sent immediately

USE SEMANTIC VERSIONING
  • MAJOR—When you make an incompatible change to the API
  • MINOR—When you make backward-compatible enhancements to the API
  • PATCH—When you make a backward-compatible bug fix

Robustness principle / Postel's law
Be conservative in what you do, be liberal in what you accept from others 
(often reworded as "Be conservative in what you send, be liberal in what you accept").

MAKING MAJOR, BREAKING CHANGES
Can let API gateway to translate old version API to new version API implementation
  1. /v1/… and  /v2/…
  2. In HTTP header, such as
    GET /orders/xyz HTTP/1.1
    Accept: application/vnd.example.resource+json; version=1 

Message formats
  1. use a cross-language message format.
  2. Ex. D NOT use Java serialization
  3. 2 main categories
    1. TEXT-BASED MESSAGE FORMATS. ex. JSON, XML
      1. Good: An advantage of these formats is that not only are they human readable, they’re self describing
      2. Bad:  
        1. the messages tend to be verbose. Ex: XML element name
        2. the overhead of parsing text, especially when messages are large
    2. BINARY MESSAGE FORMATS. Ex. Proto Buffer


Lessons Learned While Benchmarking vLLM with GPU

Recently, I benchmarked vLLM on a GPU to better understand how much throughput can realistically be expected in an LLM serving setup. One ...