adopting grpc at spotify - jfokus · adoption of grpc at spotify - jfokus 2019 - @mattgruter...

61
Adopting gRPC at Spotify @mattgruter 2019-02-06

Upload: others

Post on 08-Sep-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adopting gRPC at Spotify

@mattgruter

2019-02-06

Page 2: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

“Developersdon’t careabout new

RPC technologies”

-- someone at KubeCon 2018

Page 3: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Page 4: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adopting gRPC at Spotify

@mattgruter

2019-02-06

Page 5: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Why?

Why are we doing this?

What?

What do we get out of this?

How?

How do we get there?

Page 6: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Spotify’s Infrastructure

~2500 services

~1000 developers

~250 teams

Java, Python, ...

Page 7: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Hermes

Not this Hermes!

Page 8: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Hermes

But this

Page 9: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

HermesWritten in 2012

Based on ZeroMQ

JSON or protobuf payload

Not a RPC framework

Page 10: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Hermes works!

Page 11: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Why Change?

Page 12: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Hermes Ecosystem

Page 13: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

404 Not Found

Page 14: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

From NIH to OSS

Page 15: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Why gRPC?

Page 16: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Page 17: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Cloud Native

Page 18: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

gRPC1. HTTP/2 based

2. Binary protocol

3. Strongly typed service and message

definition (Protobuf)

4. Encryption

Page 19: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

The gRPC Advantage

Page 20: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

The Proto

Page 21: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Code Generation

Java, Golang, Python, Ruby,

Dart, PHP, Node.js,

Objective-C, C#, C++

Page 22: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Protobuf

syntax = "proto3";

package spotify.metadata.v1;

option java_package = "com.spotify.metadata.v1"

option java_multiple_files = true;

option java_outer_classname = "MetadataProto";

// Interface exported by the server.

service Metadata {

rpc GetMetadata(SongId) returns (SongMetadata) {}

}

message SongId {

int32 id = 1;

}

message SongMetadata {

int32 id = 1;

string name = 2;

string artist = 3;

string album = 4;

}

Page 23: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Server Logic(Java)

public class MetadataService extends MetadataGrpc.MetadataImplBase {

// [...]

@Override

public void getMetadata(SongId songId,

StreamObserver<SongMetadata> response) {

LOG.info("Received getMetadata request");

response.onNext(store.searchMetadata(songId)

.orElse(EMPTY_METADATA));

response.onCompleted();

}

}

Page 24: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Polyglotclient impl.

func main() {

ctx, cancel := context.WithTimeout(

context.Background(), time.Second)

defer cancel()

)

conn, err := grpc.Dial("nls://metadata")

if err != nil {

log.Fatalf("couldn't connect to grpc server: %v", err)

}

defer conn.Close()

client := pb.NewMetadataServiceClient(conn)

r, err := client.Metdata(ctx,

&pb.SongId{

Id: "42"

},

)

if err != nil {

log.Printf("metadata request failed: %v\n", err)

return

}

fmt.Println(r.Response)

}

Page 25: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,
Page 26: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Schema Management

1. Embrace the proto

2. Shared repo for all protos

3. Version on the proto level

Page 27: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Schema Management

github.com/uber/prototool

Page 28: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Resiliency

Page 29: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Deadlines

Page 30: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

A common RPC

Page 31: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Retries● Transparent ● Configurable

Page 32: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Hedging

Page 33: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Thundering Herd

Page 34: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Retry throttling

Page 35: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Load Balancing & Routing

Page 36: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Load Balancing● Client-side● Proxy● Lookaside

Page 37: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Load Balancinglookaside

Page 38: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

How to Migrate?

Page 39: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Our Journey

Hermes gRPC

Page 40: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Stats2874 Services

1341 HTTP

983 Hermes

76 gRPC

Page 41: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Our Journey

Hermes gRPC

80 servicesDistance Travelled

900 servicesRemaining Distance to Destination

Page 42: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Challenge #1

Change is hard

Page 43: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

1. Don’t force it!

Page 44: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

1. Don’t force it!

code generation

Page 45: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

1. Don’t force it!

code generation

Resiliency patterns

Page 46: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

1. Don’t force it!

code generation

Resiliency patterns

Tracing

Page 47: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

1. Don’t force it!

code generation

Resiliency patterns

Tracing

Istio

Page 48: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

2. Make the Right Choicethe Easy Choice

Page 49: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

3. Unblock & Decouple

Page 50: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,
Page 51: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Challenge #2

Yet another protocol

Page 52: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Never-ending migration

Hermes gRPC

Page 53: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Step by step1. Add a new gRPC API

2. Move clients to new API

3. Remove old API

Page 54: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Step by step1. Add a new gRPC API

2. Move clients to new API

3. Remove old API

this is hard!

Page 55: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Challenge #3

Developer experience

Page 56: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Our Journey

Hermes gRPC

80 servicesDistance Travelled

900 servicesRemaining Distance to Destination

Page 57: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Our Journey

Hermes gRPC

Page 58: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Our Journey

Hermes gRPC

Page 59: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

“Developersdon’t careabout new

RPC technologies”

-- someone at KubeCon 2018

Page 60: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Developersdon’t have care

about newRPC technologies

Page 61: Adopting gRPC at Spotify - Jfokus · Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter Spotify’s Infrastructure ~2500 services ~1000 developers ~250 teams Java, Python,

Adoption of gRPC at Spotify - Jfokus 2019 - @mattgruter

Thank You