首页 > 其他分享 >Microservice- Resiliency patterns: Retry Pattern

Microservice- Resiliency patterns: Retry Pattern

时间:2023-11-19 11:14:28浏览次数:32  
标签:retry calls service gRPC Pattern will patterns client Microservice

Retry Pattern

Transient faults occur when a momentary loss of service functionality self-corrects. The retry pattern in gRPC enables us to retry a failed call automatically and thus is perfect for transient faults such as these:
 Instant network failures
 Temporarily unavailable services
 Resource exhaustion of service due to load

gRPC has an interception mechanism that allows you to implement your interceptor and configure the gRPC client to apply the interceptor to all gRPC calls. Using the same strategy, we can execute interceptors on the gRPC server side before the request is passed to actual business logic. gRPC middleware is a good place to define the retry pattern and apply it to all gRPC calls on the client side instead of duplicating retry logic for each type of client call. Thanks to the gRPC ecosystem, a GitHub organization contains notable, community-maintained projects related to gRPC for resiliency. We will use the gRPC retry module (http://mng.bz/XNV9) of go-grpc-middleware (https://github.com/grpc-ecosystem/go-grpc-middleware) to apply retry logic to our gRPC calls.

In gRPC, there are two types of interceptor usage, WithUnaryInterceptor and WithStreamingInterceptor for unary and streaming (http://mng.bz/yQop) connections, respectively. As in listing 6.3, you can use UnaryClientInterceptor with or without values; if you don’t pass a value, it will use default values for retry, or you can override them by using additional configurations such as WithCodes, WithMax, or WithBackoff. Keep in mind that the gRPC retry configuration is handled via the grpc_retry package.

WithCodes is used for deciding when to retry, and its default value is the total of the Unavailable and ResourceExhausted lists. Unavailable code is the default since retrying until the service becomes available is beneficial for the client to recover the gRPC call once the dependent service becomes available. In the same way, ResourceExhausted is a default because the client might have performed multiple calls that caused the server to apply throttling. For this kind of case, the server will remove throttling, and the client will succeed on the next calls performed by the retry. With these defaults, the retry pattern is applied only if you get Unavailable or ResourceExhausted from the service call.

The WithMax parameter helps to set a maximum limit for retries during interservice communication. If the dependent service becomes available earlier, the client will not retry until the maximum count; it will stop once the client starts to get a response
code other than Unavailable or ResourceExhausted.

WithBackoff requires a function to specify back-off functionality between retries. In our example, BackoffLinear is used, which means there is a one-second wait time between retries. There are other options, such as BackoffExponential, in which the
timeout interval on the next retry is multiplied by two, compared to the current timeout interval. Other options are BackoffLinearWithJitter and BackoffExponentialWithJitter, in which the next timeout interval is decided randomly. This randomness reduces the collision of gRPC calls clients make. See http://mng.bz/MB1Q for the details of backoff strategies.

标签:retry,calls,service,gRPC,Pattern,will,patterns,client,Microservice
From: https://www.cnblogs.com/zhangzhihui/p/17841729.html

相关文章

  • Microservice- Resiliency patterns: Timeout Pattern
    TimeoutPatternWhatiscontext.Context?The contextinGoenablesyoutospecifydeadlines,cancellationsignals,orkey-valuepairs availablebetweenprocesses. context.WithDeadlinerequiresatargetdateasaparameter,butthereisaneasierstep: c......
  • Microservice - Load Balancing (LB)
        ......
  • Microservice - Hexagonal Architecture
    Hexagonalarchitecture(https://alistair.cockburn.us/hexagonal-architecture/),proposedbyAlistairCockburnin2005,isanarchitecturalpatternthataimstobuild looselycoupledapplicationcomponentsthatcanbeconnectedviaportsand adapters.Inth......
  • Microservice - Data Consistency
    Tohavedataconsistencyinadistributedsystem, youhavetwooptions:atwo-phasecommit(2PC)andsaga. 2PCcoordinatesallthe processesthatformdistributedatomictransactionsanddetermineswhetherthey shouldbecommittedoraborted.  As......
  • EF报错:Unable to create an object of type 'XXXXXXX'. For the different patterns s
    这个是在EF迁移的时候报错: 解决方案:修改你的MyDbcontext:  代码如下:publicclassStoreDbContexttFactory:IDesignTimeDbContextFactory<‘你的类名’>{public‘你的类名’CreateDbContext(string[]args){varoptionsBuilder=newDbContextOptionsBuilder<‘......
  • 设计模式(Design Pattern)记忆
    创建型记忆口诀:创公园,但见愁创工原,单建抽创建型工厂方法FactoryMethod原型Prototype单例Singleton建造者Builder抽象工厂AbstractFactory结构型记忆口口诀:姐想外祖,世代装桥结享外组,适代装桥结构型:享元Flyweight外观Facade组合Composite适配器Adapter装饰Decorat......
  • 无涯教程-Clojure - re-pattern函数
    re-pattern返回java.util.regex.Pattern的实例。然后将其用于其他模式匹配方法。re-pattern-语法(repatternpat)参数   - "pat"是需要形成的pattern。返回值 - 类型为java.util.regex.Pattern的模式对象。re-pattern-示例(nsclojure.examples.example......
  • From monolithic application to microservice framework
    challenges:1.versioncontrol AftertestingthebranchA,pullthelatestcode(mergedB)->confilcts?noconflicts?->regressiontesting 2. changetogolanguage3.upgradethelibrarygo1.12-go1.134.onlyonetestingserverwaitingformulti......
  • ExcelPatternTool 开箱即用的Excel工具包现已发布!
    目录ExcelPatternTool功能特点:快速开始使用说明常规类型高级类型Importable注解Exportable注解IImportOption导入选项IExportOption导出选项单元格样式StyleMapping样式映射使用数据库作为数据源示例Sample1:不同类型字段导出Sample2:高级类型导入和导出Sample3:员工健康体检工具已知......
  • c: Visitor Pattern
     /***@filevalidator.h*@authoryourname([email protected])*@brief观察者模式VisitorPattern来源:C现代编程集成开发环境、设计模式、极限编程、测试驱动开发、重构、持续集成日.花井志生著,杨文轩译,人民邮电出版社*@version0.1*@date2023-10-21......