bff pattern in action: soundcloud’s microservices

107

Upload: bora-tunca

Post on 22-Jan-2017

1.572 views

Category:

Software


0 download

TRANSCRIPT

Page 1: BFF Pattern in Action: SoundCloud’s Microservices
Page 2: BFF Pattern in Action: SoundCloud’s Microservices

BFF Pattern in ActionSoundCloud’s Microservices

Page 3: BFF Pattern in Action: SoundCloud’s Microservices

Bora Tunca

Joined SoundCloud 2.5 years ago

soundcloud.com front-end

client specific apis

core-services

@grandbora

Page 4: BFF Pattern in Action: SoundCloud’s Microservices

SoundCloud is the largest online audio distribution platform

Page 5: BFF Pattern in Action: SoundCloud’s Microservices

12 HOURS OF AUDIOevery minute

Page 6: BFF Pattern in Action: SoundCloud’s Microservices
Page 7: BFF Pattern in Action: SoundCloud’s Microservices
Page 8: BFF Pattern in Action: SoundCloud’s Microservices

MOTHERSHIP

Page 9: BFF Pattern in Action: SoundCloud’s Microservices

MOTHERSHIP

Public API

Page 10: BFF Pattern in Action: SoundCloud’s Microservices

MOTHERSHIP

Public API

messages

likes

Page 11: BFF Pattern in Action: SoundCloud’s Microservices

MOTHERSHIP

Public API

messages

likes

Page 12: BFF Pattern in Action: SoundCloud’s Microservices

Mic

rose

rvic

es

0

20

40

60

80

100

120

2013 2014 2015 2016

Page 13: BFF Pattern in Action: SoundCloud’s Microservices

Mic

rose

rvic

es

0

20

40

60

80

100

120

2013 2014 2015 2016

Page 14: BFF Pattern in Action: SoundCloud’s Microservices

Mic

rose

rvic

es

0

20

40

60

80

100

120

2013 2014 2015 2016

Page 15: BFF Pattern in Action: SoundCloud’s Microservices

Mic

rose

rvic

es

0

20

40

60

80

100

120

2013 2014 2015 2016

Page 16: BFF Pattern in Action: SoundCloud’s Microservices

http://martinfowler.com/bliki/HumaneRegistry.html

Page 17: BFF Pattern in Action: SoundCloud’s Microservices

Humane Registry

Page 18: BFF Pattern in Action: SoundCloud’s Microservices

Oriented around people

Humane Registry

Page 19: BFF Pattern in Action: SoundCloud’s Microservices

Oriented around people

Don't rely on people to stay up to date

Humane Registry

Page 20: BFF Pattern in Action: SoundCloud’s Microservices

Oriented around people

Don't rely on people to stay up to date

Expect humans to read and contribute

Humane Registry

Page 21: BFF Pattern in Action: SoundCloud’s Microservices

SERVICES DIRECTORY

Page 22: BFF Pattern in Action: SoundCloud’s Microservices
Page 23: BFF Pattern in Action: SoundCloud’s Microservices
Page 24: BFF Pattern in Action: SoundCloud’s Microservices

Public API

messages

likesMOTHERSHIP

Page 25: BFF Pattern in Action: SoundCloud’s Microservices
Page 26: BFF Pattern in Action: SoundCloud’s Microservices

Api-v2 Api-mobile Api-embedded Public API

Page 27: BFF Pattern in Action: SoundCloud’s Microservices

Api-v2 Api-mobile Api-embedded Public API

messages

MOTHERSHIPlikes

search

stats

images

Page 28: BFF Pattern in Action: SoundCloud’s Microservices

Api-v2 Api-mobile Api-embedded Public API

Edge Layer

messages

MOTHERSHIPlikes

search

stats

images

Page 29: BFF Pattern in Action: SoundCloud’s Microservices

Api-v2 Api-mobile Api-embedded Public API

Edge Layer

Client Applications

Microservices

messages

MOTHERSHIPlikes

search

stats

images

Page 30: BFF Pattern in Action: SoundCloud’s Microservices

Backend For Fronted

Page 31: BFF Pattern in Action: SoundCloud’s Microservices
Page 32: BFF Pattern in Action: SoundCloud’s Microservices

Microservices

Page 33: BFF Pattern in Action: SoundCloud’s Microservices

BFFs

Microservices

Page 34: BFF Pattern in Action: SoundCloud’s Microservices

Client ApplicationsBFFs

Microservices

Page 35: BFF Pattern in Action: SoundCloud’s Microservices

BFF

Page 36: BFF Pattern in Action: SoundCloud’s Microservices

BFF authentication geo location features

1

Page 37: BFF Pattern in Action: SoundCloud’s Microservices

BFF

messages

MOTHERSHIPlikes

search

stats

images

2

authentication geo location features

1

Page 38: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

Page 39: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

Page 40: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

Page 41: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

Page 42: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

Page 43: BFF Pattern in Action: SoundCloud’s Microservices

BFF

messages

MOTHERSHIPlikes

search

stats

images

2

authentication geo location features

1

Page 44: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

BFF

BFFBFF

BFFBFF

Page 45: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

BFF

BFFBFF

BFFBFF

Critical Path

Page 46: BFF Pattern in Action: SoundCloud’s Microservices

On critical path…

Page 47: BFF Pattern in Action: SoundCloud’s Microservices

Be ready for traffic bursts

On critical path…

Page 48: BFF Pattern in Action: SoundCloud’s Microservices

Be ready for traffic bursts

Handle failures gracefully

On critical path…

Page 49: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

1

Page 50: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

authentication geo location features

1

2

Page 51: BFF Pattern in Action: SoundCloud’s Microservices

Public API

messages

likesMOTHERSHIP

Page 52: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

Page 53: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

BFF

Page 54: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

BFF

Page 55: BFF Pattern in Action: SoundCloud’s Microservices

messages

MOTHERSHIP

BFF

likes

search

stats

images

tracks

BFF

Page 56: BFF Pattern in Action: SoundCloud’s Microservices
Page 57: BFF Pattern in Action: SoundCloud’s Microservices

images userstracks

Foundation Layer

Page 58: BFF Pattern in Action: SoundCloud’s Microservices

images userstracks

Foundation Layer

playlistsstream profiles

Value Added Layer

Page 59: BFF Pattern in Action: SoundCloud’s Microservices

images userstracks

Foundation Layer

playlistsstream profiles

Value Added Layer

Page 60: BFF Pattern in Action: SoundCloud’s Microservices

images userstracks

Foundation Layer

playlistsstream profiles

Value Added Layer

Page 61: BFF Pattern in Action: SoundCloud’s Microservices

BFF BFF

images userstracks

Foundation Layer

playlistsstream profiles

Value Added Layer

Page 62: BFF Pattern in Action: SoundCloud’s Microservices

BFF BFF

images userstracks

Foundation Layer

playlistsstream profiles

Value Added Layer

MOTHERSHIP

Page 63: BFF Pattern in Action: SoundCloud’s Microservices
Page 64: BFF Pattern in Action: SoundCloud’s Microservices
Page 65: BFF Pattern in Action: SoundCloud’s Microservices

GRAPHITE

STATSD

Page 66: BFF Pattern in Action: SoundCloud’s Microservices

GRAPHITE

STATSD

PROMETHEUS

Page 67: BFF Pattern in Action: SoundCloud’s Microservices

Prometheus

Scalable data collection

Operational simplicity

Multi-dimensional data

Powerful query language

https://developers.soundcloud.com/blog/prometheus-monitoring-at-soundcloudhttp://prometheus.io/

Page 68: BFF Pattern in Action: SoundCloud’s Microservices

Prometheus

Page 69: BFF Pattern in Action: SoundCloud’s Microservices

Prometheus

My Service

Page 70: BFF Pattern in Action: SoundCloud’s Microservices

Prometheus

My Service

http://instance-url/metrics

Page 71: BFF Pattern in Action: SoundCloud’s Microservices

Prometheus

My Service

http://instance-url/metrics

Page 72: BFF Pattern in Action: SoundCloud’s Microservices

Prometheus

My Service

http://instance-url/metrics

jvm client

Page 73: BFF Pattern in Action: SoundCloud’s Microservices
Page 74: BFF Pattern in Action: SoundCloud’s Microservices
Page 75: BFF Pattern in Action: SoundCloud’s Microservices

Prometheus

My Service

jvm client

My Service

jvm client

My Service

jvm client

My Service

jvm client

My Service

jvm client

My Service

jvm client

My Service

jvm client

My Service

jvm client

My Service

jvm client

My Service

jvm client

Page 76: BFF Pattern in Action: SoundCloud’s Microservices
Page 77: BFF Pattern in Action: SoundCloud’s Microservices

val requestCount = telemetry.counter("outgoing_http_requests_total", "A counter for the HTTP requests", "service", "method", "status", "statusClass")

send

requestCount.labels( serviceName, request.getMethod, response.getStatus, response.getStatusClass).inc()

Page 78: BFF Pattern in Action: SoundCloud’s Microservices

val requestCount = telemetry.counter("outgoing_http_requests_total", "A counter for the HTTP requests", "service", "method", "status", "statusClass")

send

requestCount.labels( serviceName, request.getMethod, response.getStatus, response.getStatusClass).inc()

query SUM(rate(outgoing_http_requests_total{statusClass!="2xx"}[10m])) by (service, method, status)

Page 79: BFF Pattern in Action: SoundCloud’s Microservices
Page 80: BFF Pattern in Action: SoundCloud’s Microservices
Page 81: BFF Pattern in Action: SoundCloud’s Microservices

DISTRIBUTED TRACING

Page 82: BFF Pattern in Action: SoundCloud’s Microservices
Page 83: BFF Pattern in Action: SoundCloud’s Microservices

SERVICE LEVEL OBJECTIVES

Page 84: BFF Pattern in Action: SoundCloud’s Microservices

manifest.json{ "name": "trackmetadata", "type": "internal_service", "description": "Track Metadata service", "contact_email": "xxxxxxx", "owner": "core-services", "status": "production", "alert_service": "pagerduty.com/xxxx", "telemetry_dashboard": "http://promdash/trackmetadata", "data_sensitivity": xxxx, "dependencies": xxxx, "slo": { "error_rate_threshold": 0.1, "latency_p99_threshold_seconds": 0.02, "availability_target": 0.99999, "metrics_server": "http://prometheus/trackmetadata" }}

Page 85: BFF Pattern in Action: SoundCloud’s Microservices

manifest.json{ "name": "trackmetadata", "type": "internal_service", "description": "Track Metadata service", "contact_email": "xxxxxxx", "owner": "core-services", "status": "production", "alert_service": "pagerduty.com/xxxx", "telemetry_dashboard": "http://promdash/trackmetadata", "data_sensitivity": xxxx, "dependencies": xxxx, "slo": { "error_rate_threshold": 0.1, "latency_p99_threshold_seconds": 0.02, "availability_target": 0.99999, "metrics_server": "http://prometheus/trackmetadata" }}

Page 86: BFF Pattern in Action: SoundCloud’s Microservices

manifest.json{ "name": "trackmetadata", "type": "internal_service", "description": "Track Metadata service", "contact_email": "xxxxxxx", "owner": "core-services", "status": "production", "alert_service": "pagerduty.com/xxxx", "telemetry_dashboard": "http://promdash/trackmetadata", "data_sensitivity": xxxx, "dependencies": xxxx, "slo": { "error_rate_threshold": 0.1, "latency_p99_threshold_seconds": 0.02, "availability_target": 0.99999, "metrics_server": "http://prometheus/trackmetadata" }}

Page 87: BFF Pattern in Action: SoundCloud’s Microservices

manifest.json{ "name": "trackmetadata", "type": "internal_service", "description": "Track Metadata service", "contact_email": "xxxxxxx", "owner": "core-services", "status": "production", "alert_service": "pagerduty.com/xxxx", "telemetry_dashboard": "http://promdash/trackmetadata", "data_sensitivity": xxxx, "dependencies": xxxx, "slo": { "error_rate_threshold": 0.1, "latency_p99_threshold_seconds": 0.02, "availability_target": 0.99999, "metrics_server": "http://prometheus/trackmetadata" }}

Page 88: BFF Pattern in Action: SoundCloud’s Microservices
Page 89: BFF Pattern in Action: SoundCloud’s Microservices

RECAP

Page 90: BFF Pattern in Action: SoundCloud’s Microservices

RECAP

Knowledge sharing

Page 91: BFF Pattern in Action: SoundCloud’s Microservices

RECAP

Knowledge sharing

Evolving the architecture

Page 92: BFF Pattern in Action: SoundCloud’s Microservices

RECAP

Knowledge sharing

Evolving the architecture

Monitoring

Page 93: BFF Pattern in Action: SoundCloud’s Microservices

backstage.soundcloud.com

@pcalcado - How we ended up with microservices

@starcoffe - Why SoundCloud stopped using its own public API

InfoQ - Moving from a Monolith to Microservices at SoundCloud

Page 94: BFF Pattern in Action: SoundCloud’s Microservices

Netflix API Gateway Pattern

http://techblog.netflix.com/2013/01/optimizing-netflix-api.html

Page 95: BFF Pattern in Action: SoundCloud’s Microservices

http://samnewman.io/patterns/architectural/bff/

https://www.thoughtworks.com/insights/blog/bff-soundcloud

Page 96: BFF Pattern in Action: SoundCloud’s Microservices

[email protected]

https://soundcloud.com/jobs

Thank you!

@grandbora

Page 97: BFF Pattern in Action: SoundCloud’s Microservices
Page 98: BFF Pattern in Action: SoundCloud’s Microservices
Page 99: BFF Pattern in Action: SoundCloud’s Microservices
Page 100: BFF Pattern in Action: SoundCloud’s Microservices
Page 101: BFF Pattern in Action: SoundCloud’s Microservices
Page 102: BFF Pattern in Action: SoundCloud’s Microservices
Page 103: BFF Pattern in Action: SoundCloud’s Microservices
Page 104: BFF Pattern in Action: SoundCloud’s Microservices
Page 105: BFF Pattern in Action: SoundCloud’s Microservices
Page 106: BFF Pattern in Action: SoundCloud’s Microservices
Page 107: BFF Pattern in Action: SoundCloud’s Microservices