microservices at mercari

72
Microservices at Mercari Current status and challenges

Upload: google-cloud-platform-japan

Post on 21-Jan-2018

10.881 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Microservices at Mercari

Microservices at MercariCurrent status and challenges

Page 2: Microservices at Mercari

Taichi Nakashima (@deeeet/@tcnksm)

SRE at Mercari, automation obsessed, gopher

Page 3: Microservices at Mercari

SRE mission at Mercari

● To ensure a reliable service that is enjoyable to use at anytime● Takes care of all engineering apart from new service development

○ Performance improvement, automation, security etc

Page 4: Microservices at Mercari

Current Mercari architecture

nginx

HTTP

API API API

MySQL MySQL

solr solr solr

Cache

Simple 3 tiler + α architecture

Single code base

Page 5: Microservices at Mercari

Current Mercari architecture

Same architectureIn 3 region

JPUS

UK

Page 6: Microservices at Mercari

Positive

● A central ops team (SRE) can efficiently handle

Page 7: Microservices at Mercari

Challenges

Page 8: Microservices at Mercari

Challenges

nginx

HTTP

API API API

MySQL MySQL

solr solr solr

Cache

Simple 3 tiler + α architecture

Single code base

Page 9: Microservices at Mercari

Challenges

nginx

HTTP

API API API

MySQL MySQL

solr solr solr

Cache

Simple 3 tiler + α architecture

Monolith?

Page 10: Microservices at Mercari

Challenges

● Code is too huge/complex to understand ● Team is too large to efficiently work on shared code base● Communication overhead is too large ● Velocity (development cycle) is stalled...

Page 11: Microservices at Mercari

Microservices

Page 12: Microservices at Mercari

Microservices?

● Architectural and organizational approach to software development○ To speed up deployment cycles○ Foster innovation and ownership ○ Improve maitainability and scalability

Page 13: Microservices at Mercari

Microservices?

$ cat inside.txt | cut -f 1 -d ' ' | sort | uniq -c | sort -nr

Page 14: Microservices at Mercari

Microservices

● Do one thing well ○ Unix philosophy○ One function in one service, not multiple functions in one service

● Decentralized Governance○ Each team has ownership on each service

● Independent○ Each service can be changed, upgraded, or replaced independently

● Polyglot○ Right framework and tool for each domain

Page 15: Microservices at Mercari

Goal

● Software Engineer○ Without velocity stalled, rather make feature improvement iteration speed fast ○ -> Provide great features to customers faster

● SRE ○ Provide automated platform for microservice ○ Give some responsibility (e.g., deployment, debug) to software engineering○ -> Focus on more SRE related software engineering task

Page 16: Microservices at Mercari

Team

@deeeet @spensnova @babarot

Page 17: Microservices at Mercari

State of microservices in US

Page 18: Microservices at Mercari

Microservices architecture in US

Mercari API

HTTP

Page 19: Microservices at Mercari

Microservices architecture in US

Gateway API

Mercari API

HTTP

HTTP

Page 20: Microservices at Mercari

Microservices architecture in US

Gateway API

Mercari API

HTTP

offer

HTTP

gRPC

Page 21: Microservices at Mercari

Microservices architecture in US

Gateway API

Mercari API

HTTP

search offer

HTTP

gRPC

Page 22: Microservices at Mercari

Microservices architecture in US

Gateway API

Mercari API

HTTP

search

personalization

offer

HTTP

gRPC

Page 23: Microservices at Mercari

Technical stacks

● Docker● Kubernetes (Google Container Engine) ● gRPC

Page 24: Microservices at Mercari

Container

● Resource isolation● Resource limitation● Fast boot (vs. VM)

Docker

● Easy to build container image● Easy to distribute via registry

Page 25: Microservices at Mercari

Why Docker?

● Software engineer control more○ They can include what they want (e.g., runtime, library)

● Environmental parity○ What works on local development (or QA env) is exact same (easy to debug)○ No more “it works on my environment but not in production!”

● Easy to deploy○ Docker image ≒ Single static linked binary○ You already know its benefit if you use Go

Page 26: Microservices at Mercari

Kubernetes (GKE)

● Container orchestration● Derives from Google internal

system named Borg & Omega● Inspired and informed by

Google’s experiences and internal systems

Page 27: Microservices at Mercari

Why kubernetes?

● Best way to maximize container benefit○ Resource isolation/limitation enables us compute resource utilization. But how?

■ K8s can correctly schedule container proper instances○ How to communicate between dynamically scheduled containers?

■ K8s provide the service discovery

● Reduce operation costs ○ Self healing & auto scaling

● Infrastructure of infrastructure○ Industrial standard https://githubengineering.com/kubernetes-at-github○ More tools/software comes top on k8s in future (I guess)

Page 28: Microservices at Mercari

gRPC

● gRPC Remote Procedure Call● High performance, general

purpose, open source, standards-based, RPC framework

● Open source version of stubby RPC in used in Google

Page 29: Microservices at Mercari

gRPC

● Simple service definition○ By default, gRPC uses protocol buffers as the Interface Definition Language (IDL) for

describing both the service interface and the structure of the payload messages.

● Works across languages and platforms○ Write golang server and python client○ Utilize polyglot microservices

Page 30: Microservices at Mercari

Why not REST?

● Who can implement REST correctly?○ High cost to design (Path? Parameters? hah?)○ Eventually it’s just HTTP endpoints

● No more HTTP client implementation ..

Page 31: Microservices at Mercari

Challenges

Page 32: Microservices at Mercari

Challenges

● Deployment ● Observability

Page 33: Microservices at Mercari

Deployment

● Deployment is key in microservices platform○ “Without velocity stalled, rather make iteration speed faster”

● We need easy & safe automated deployment system○ We started chatbot style deployment but it was not scale

Page 34: Microservices at Mercari

Spinnaker

● Continuous Delivery platform● Developed in Netflix

○ Worked with Google and open sourced in 2015

● Support multi cloud○ Kubernetes!, GCE, AWS

Page 35: Microservices at Mercari

Spinnaker GUI

Page 36: Microservices at Mercari

Spinnaker pipeline

Page 37: Microservices at Mercari

Why Spinnaker?

● Kubernetes support● Built-in deployment best practice from Netflix and Google

○ Immutable infrastructure○ Blue/Green deployment, Canary deployment○ Manual judgement (by manager) phase○ Run integration tests

Page 38: Microservices at Mercari

Spinnaker in Mercari

● Currently only for container deployment to kubernetes● Each team uses spinnaker to deploy their own services● One spinnaker handles all microservices in all region

Page 39: Microservices at Mercari

Example pipeline of API gateway deployment (Canary)

Page 40: Microservices at Mercari

One spinnaker cluster manages Mercari global deployment

JPUS

UK

Page 41: Microservices at Mercari

Future of spinnaker

● Pipeline as a Code○ https://github.com/spinnaker/dcd-spec

● Automated canary analysis

Page 42: Microservices at Mercari

Automated canary analysis

https://blog.spinnaker.io/can-i-push-that-building-safer-low-risk-deployments-with-spinnaker-a27290847ac4

Page 43: Microservices at Mercari

Observability

Observability (logging, metrics & tracing) is important

● Each team needs to debug service by themselves without SSH● It’s harder and more complex than monolith

Page 44: Microservices at Mercari

Stackdriver logging

Page 45: Microservices at Mercari

Request ID in log

● Which service caused problem in one request?

Page 46: Microservices at Mercari

Request ID in log

Gateway API

Mercari API

HTTP

search

personalization

offer

HTTP

gRPC

① Generate unique ID

② Annotate log by the ID in same request

HTTP headergRPC metadata

Page 47: Microservices at Mercari

Request ID in log

Search by request ID

Log from gateway

Log from service X

Page 48: Microservices at Mercari

Distributed tracing

● Which services makes the request slow?

Page 49: Microservices at Mercari

Stackdriver tracing

Page 50: Microservices at Mercari

Metrics

Selection of metrics service/software is still on-going discussion & trial

● First support of container and kubernetes ● Integration with kubernetes ecosystem

○ Spinnaker, istio and so on

● Service dependency visualization

Page 51: Microservices at Mercari

Prometheus + grafana

Page 52: Microservices at Mercari

Datadog

Page 53: Microservices at Mercari

Instana

Page 54: Microservices at Mercari

State of microservices in JP

Page 55: Microservices at Mercari

State of microservices in JP

JP is just started

● Some services (Machine learning product) are started to containerized and deployed on GKE

● On-going discussion about the best architecture

Page 56: Microservices at Mercari

Conclusion

● Why we started microservices?● Current state of US microservices and challenges

Page 57: Microservices at Mercari

We’re hiring

● Who loves automation● Technical keywords

○ Docker○ Kubernetes○ gRPC○ Golang ○ Container monitoring

Page 58: Microservices at Mercari
Page 59: Microservices at Mercari

Spinnaker is deployed on GKE

Page 60: Microservices at Mercari

Testing

Testing in microservice is hard?

● Focus on unit tests as usual○ Because each service is supposed to independent ○ Each microservices must measure testing coverage

● Integration tests?○ Use mock instead of working hard for preparing local env

Page 61: Microservices at Mercari

Testing pyramid

Google Testing Blog: Just Say No to More End-to-End Tests

Do this a lot !

Do mock

Page 62: Microservices at Mercari

QA environment

How to test development feature from QA device?

● Pull request (PR) based pod creation

Page 63: Microservices at Mercari

PR based pod creation

Proxy API gateway (master)

API gateway (PR 313)

API gateway (PR 314)

Proxy by PR number

Set RP number

Container is deployed via CI

Page 64: Microservices at Mercari

PR based docker container (QA env)

Easy to switch

Page 65: Microservices at Mercari

PR based pod creation

Proxy API gateway (master)

API gateway (PR 313)

API gateway (PR 314)

Service A (master)

Service A (PR 21)

Proxy by PR number

Set RP number

Container is deployed via CI

Page 66: Microservices at Mercari

Future works

Page 67: Microservices at Mercari

Service mesh

Don’t trust each other!

● Traffic management○ API rate limit, circuit breaker

● Policy enforcement○ Ensure access policies (which service can access which service?)

We should realize above without modifying client/server code!

Page 68: Microservices at Mercari

Service mesh (Istio)

https://istio.io/

Page 69: Microservices at Mercari

Service mesh (Istio)

Page 70: Microservices at Mercari

Chaos engineering

● Real world is hard … ○ machine is crashed, network is unstable (especially in distributed system)

● Dependent service fails anytime

Page 71: Microservices at Mercari

Chaos engineering

● Service must be fault tolerance whenever something wrong● Emulate real world problem

○ We need to identify weaknesses ■ Improper fallback settings when a service is unavailable

○ Software Engineer should be aware

Page 72: Microservices at Mercari

Chaos engineering (Chaos monkey)

https://github.com/Netflix/chaosmonkey