Distributed Systems

 

Jalex Chang

2019.05.17

The Sidecar Pattern ​

Jalex Chang

- Backend Engineer @ Umbo Computer Vision

- Taiwan Data Engineering Association Member

- Golang Taiwan Member

Contact:

- jalex.cpc @ Gmail

- jalex.chang @ Facebook

- JalexChang @ GitHub

- Introduction to the sidecar pattern

- A few case study in Umbo CV

- Conclusion

 

Agenda

The sidecar

A sidecar is a one-wheeled device attached to the side of a motorcycle. (Wiki)

 

The sidecar pattern in Microservices

Advantages

  • Keep application logic intact and maintainable

    • Carry on extra trivial tasks

    • Simplify the complexity of service design

  • ​Secure or access control of the application service

    • Network traffic filtering

    • Protocol transfer

      • e.g. Redis's in-transit encryption

  • Reusability of components

    • ​Common logic is reusable across similar application services

  • ​Explicit service boundary

    • ​Programming language separating

Use cases 

  • Adapt legacy applications

  • Modularity and reuse of the components

  • Configuration synchronization

  • Automatic service update

  • TLS/SSL termination
    • Circuit breaking, routing, and monitoring
  • ​Log collector
  • Proxy and caching

Sidecar Example 1

Adding HTTPS to a legacy service

Sidecar Example 2

Configuration synchronization

Camera config caching service

Case study in Umbo CV

There are too many RESTful API calls querying camera configurations from our CV pipeline and video streaming services ......

 
  • Actually, camera info would not be changed frequently.

  • But, we still want our services to get updates asap. 
 

CornerBear is born

CornerBear is a sidecar caching service for Media Server and CV Router aims to help them manage cameras' info and notify changes for registered events.

 

Even a sidecar, we still need to design its architecture strictly.

Service log collector

Case study in Umbo CV

Network is unreliable

You have no idea what a network request may meet during its journey.

If services fail to log, should they handle errors by themselves?

e.g. Retry sending, message buffering ...etc

Sidecar for log collection

  • Apply Fluentd as a sidecar logger collector.
  • Event-based, interval flushing, and autonomy.

Principles of the sidecar design

To be successful, a sidecar should be simple but flexible.

  • One sidecar, one goal

  • Modularity and reusability matter

Modularity and Reusability

  • Parameterizing your services

    • ​Configure them through environment variables or CLI

  • Define the compatible API surface

    • ​In microservices, API is the only way to do service communication.

    • Both backward and forward compatible is important.

  • Documenting your services

    • Ensuring developers can use them in the first place.

    • At least, you should provide an API doc or README.

What have we learned today?

  • The sidecar motocross is dangerous.

  • The sidecar pattern is helpful to reduce system complexity by reusing common logic and abstracting trivial tasks.

  • Service design matters in both performance and maintenance.

  • In Umbo, we are really keen on adopting and practicing state-of-the-art software engineering ways to improve products and our career paths.  

Q&A Time

Thanks for listening