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


沒有留言:

張貼留言

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法...