Building Microservices with Go

how?

  • seamless

  • efficient

  • robust

1. Introduction to Microservices

go http的基本内容,也没什么概念介绍.

2. Designing a Great API

怎样的API算great?

几个概念:

  • URI

    • URL是一种URI

    • 几个原则

      • 中间用/分隔

      • 末尾不要留/

      • -连接单词

      • 不要用_

      • 用小写字母

    • restful设计

      • Collections

        • GET /cats 所有猫的集合

        • GET /cats/1 id为1的猫

      • Documents

        • GET /cats/1/kittens 属于1的所有小猫

        • GET /cats/1/kittens kitten 1 for cat 1

      • Controller

        • POST /cats/1/feed 投喂猫1

        • POST /cats/1/feed?food=fish 投喂鱼给猫1

      • Store

        • PUT /cats/2 更新id2

    • URI query 设计

      • 分页

      • 过滤

      • 排序

  • Path

  • Query

版本

  • API

    • /v1/users/xxx

    • /users/xxx?api-version=1

  • RPC

    • Greet.v1.HelloWorld

3. Docker

简化building, shipping, running.

https://www.redhat.com/en/blog/history-containers

docker网络模式

  • bridge

  • host

  • none

  • overlay

4. Testing

5. Common Patterns

模式:

  • 事件处理

    • 最少一次消息处理

      • 消息队列

      • 错误处理

        • 没有处理成功的消息带着错误信息放回队列(应该带尝试次数)

      • dead letter queue

        • 没有处理成功的消息丢在这里, 用来debug

    • 幂等事务,时序

      • 记录message id, 每次检查

    • 原子事务

  • 超时

    • 网络连接超时

    • 请求超时

  • Back off

    • 避免连续重试造成的雪崩

  • Circuit breaking

    • 系统承压时, 自动降级

    • 错误超过阈值, 自动断路返回失败, ,错误降低再恢复

  • Health checks

  • Throttling

    • 限流

  • Service discovery

  • Load balancing

  • Caching

6. Microservice Frameworks

7. Logging and Monitoring