104
Jose Nino @junr03 Next Generation Client APIs with Envoy Mobile QCon London - March 2020 Some slides built in collaboration with: @goaway & @rebello95

Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Jose Nino@junr03

Next Generation Client APIs with Envoy MobileQCon London - March 2020

Some slides built in collaboration with: @goaway & @rebello95

Page 2: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Server

Networking

Networking

Client

@rebello95

Page 3: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Server

Networking

Networking

Client

@junr03

API

Page 4: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Server

Networking

Networking

Server

@junr03

Server

Networking

Server

Networking

Server

Networking

Server

Networking Server

NetworkingServer

NetworkingServer

Networking

Server

Networking

Page 5: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Service

Networking

Networking

Server

@junr03

API

Server

Networking

Service

Networking

Server

Networking

Service

Networking Service

NetworkingService

NetworkingServer

Networking

Server

Networking

Service

Networking

Server

Networking Server

Networking

Server

Networking

Server

Networking

Server

Networking Server

Networking

Server

Networking

Server

Networking

Server

Networking Service

Networking

Server

Networking

Service

Networking

Server

Networking Server

Networking

Server

Networking

Page 6: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Service

Networking

Networking

Server

@junr03

API

Server

Networking

Service

Networking

Server

Networking

Service

Networking Service

NetworkingService

NetworkingServer

Networking

Server

Networking

Service

Networking

Server

Networking Server

Networking

Server

Networking

Server

Networking

Server

Networking Server

Networking

Server

Networking

Server

Networking

Server

Networking Service

Networking

Server

Networking

Service

Networking

Server

Networking Server

Networking

Server

Networking

����

������

��

Page 7: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Jose Nino@junr03

Infrastructure Engineer

~4 years @

Page 8: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Service

Networking

Networking

Server

@junr03

API

Server

Networking

Service

Networking

Server

Networking

Service

Networking Service

NetworkingService

NetworkingServer

Networking

Server

Networking

Service

Networking

Server

Networking Server

Networking

Server

Networking

Server

Networking

Server

Networking Server

Networking

Server

Networking

Server

Networking

Server

Networking Service

Networking

Server

Networking

Service

Networking

Server

Networking Server

Networking

Server

Networking

����

������

��

Page 9: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Server

Networking

Networking

Client

@junr03

API

Page 10: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

We recognized two important dimensions in API management: what data we send (shape), and how we send it (transport).

@junr03

~3 years in Server Networking

Page 11: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Server-side Interface Definition Language (IDL)

Service A“server”

@junr03

#service_a.proto

service ServiceA {

rpc UpdateA(ARequest) returns (AResponse) {

option (http.http_options).path = "/service_a";

option (http.http_options).method = "POST";

}

}

Service B “client”

Page 12: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

● Network Proxy driven by Open-source

(OSS) community

● Common substrate for network behavior

What is ?

@junr03

Sidecar

Service B “client”

Sidecar

Service A“server”

Page 13: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Storage

EdgeMobile Client

Sidecar

Service B

Sidecar

Service A

3rd-party

Strongly-typed APIs and a Universal Network Primitive

@junr03

Page 14: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

(circa early 2019)

The End

@junr03

Page 15: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Storage

EdgeMobile Client

Sidecar

Service B

Sidecar

Service A

3rd-party��

Strongly-typed APIs and a Universal Network Primitive

@junr03

Page 16: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only

able to complete the desired product flows a fraction of the time.

What do we want from our Client APIs?

@junr03

Page 17: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Consistency ? ✓

Performance ? ✓

Extensibility ? ✓

Resilience ? ✓

Security ? ✓

Observability ? ✓

Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product flows a fraction of the time.

What do we want from our Client APIs?

@junr03

Page 18: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Storage

Edge

Sidecar

Service B

Sidecar

Service A

3rd-party

Clients as another node in the mesh

Mobile Client

@goaway @junr03

API

Page 19: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Next generation Client APIs with Envoy Mobile

Mobile Client

@junr03

API

��We recognized two important dimensions in API management: what data we send (shape), and how we send it (transport).

~1 year in Client Networking

Page 20: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

We recognized two important dimensions in API management: what data we send (shape), and how we send it (transport).

@junr03

API Shape

Page 21: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Early API workflow at Lyft

Tech spec

handwritten.swift

handwritten.kt

handwritten.py/.go

@rebello95

Page 22: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

iOS

Server

{ “key_a”: “hello”}

Android

{ “kye_a”: “hello”}

Programming errors

@rebello95

Page 23: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

iOS

Server

{ “key_a”: “hello”}

Android

{ “kye_a”: “hello”}

Programming errors

@rebello95

Page 24: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

iOS

Server

{ “key_a”: “hello”}

Android

{ “kye_a”: “hello”}

Programming errors

@rebello95 @junr03

��

Page 25: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

iOS

Server

{ “key_a”: “hello”}

Android

{ “kye_a”: “hello”}

Programming errors

@rebello95 @junr03

Page 26: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

iOS

Server

{ “key_a”: “hello”}

Android

{ “kye_a”: “hello”}

if (android):else:

Programming errors

@rebello95

Page 27: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

● Handwritten code led to mistakes/typos

● No visibility into deserialization failures at compile time

Problems

@rebello95 @junr03

Page 28: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

YAML schema integration

@rebello95

Page 29: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

paths:

/foo:

post:

parameters:

- in: body

schema:

$ref: '#/definitions/FooRequest'

responses:

200:

schema:

$ref: '#/definitions/FooResponse'

YAML definitions

@rebello95

Page 30: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

● Manual code generation for Android

● No integration on iOS

● No single source of truth

YAML results

@rebello95

Page 31: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Consistency

@rebello95 @junr03

We needed a source of truth that provided guarantees about the shape of

any given API.

Page 32: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Envisioned workflow

Tech spec IDL repo

foo_api.swift

foo_api.kt

foo_api.py/.go

foo_api.proto

@rebello95

Page 33: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

● Platform-neutral IDL for defining and serializing strongly-typed APIs.

● JSON support (migration)

● Already used server-side (consistency)

Why protobuf?

@rebello95 @junr03

Page 34: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

IDL pipeline

/api/v1/foo.proto

Generators

+7 others

foo.go

foo.py

foo.kt

foo.swift

@rebello95

Page 35: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

IDL pipeline

/api/v1/foo.proto

Generators

+7 others

foo.go

foo.py

foo.kt

foo.swift FooV1API library

foo-v1-api library

@rebello95

Page 36: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Using generated APIs in Swift

@rebello95

Page 37: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

// Modules/FooV1API/FooAPI.swift

public struct FooRequest: Codable, Equatable { … }

public struct FooResponse: Codable, Equatable {

public let id: Int64

public let firstName: String

}

Generated models

@rebello95

Page 38: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

// Modules/FooV1API/FooAPI.swift

import RxSwift

public protocol FooAPI {

func updateFoo(_ request: FooRequest)

-> Single<Result<FooResponse, FooAPIError>>

}

public struct FooClientAPI: FooAPI {

// Abstracted implementation

}

Generated APIs

@rebello95

Page 39: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

// Modules/FooV1API/FooAPI.swift

import RxSwift

public protocol FooAPI {

func updateFoo(_ request: FooRequest)

-> Single<Result<FooResponse, FooAPIError>>

}

public struct FooClientAPI: FooAPI {

🌟 // Abstracted implementation 🌟 (hint hint wink wink!)

}

Generated APIs

@rebello95 @junr03

Page 40: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

// Modules/FooV1APIMock/FooAPI.swift

open class FooMockAPI: FooAPI {

open lazy var mockUpdateFoo: (FooRequest)

-> Result<FooResponse, FooAPIError> = { … }

open func updateFoo(_ request: FooRequest)

-> Single<Result<FooResponse, FooAPIError>> { … }

}

Generated mocks

@rebello95

Page 41: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

● Single source of truth for all APIs

● Consistent, generated code on all platforms

● Highly testable

● Underlying transport fully abstracted 🌟 565958

Results

@rebello95

Page 42: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Performance

@rebello95 @junr03

Experimenting with payload encoding

Page 43: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Client

Service

JSON request

Existing system

JSON response

@rebello95

Page 44: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Client

Service

JSON requestContent-Type: json

Accept: x-protobuf,json

Content negotiation

MiddlewareJSON > Protobuf

Protobuf requestContent-Type: x-protobuf

Protobuf responseContent-Type: x-protobuf

MiddlewareNo change

Protobuf responseContent-Type: x-protobuf

@rebello95

Page 45: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

JSON

Protobuf

@rebello95

Page 46: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

● 40%+ reduction in payload sizes

● Faster response times

● Higher success rates

● Transparent to engineers

Wins from protobuf

@rebello95

Page 47: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product flows a fraction of the time.

What do we want from our Client APIs?

@junr03

Consistency ✓ ✓

Performance ✓ ✓

Extensibility ? ✓

Resilience ? ✓

Security ? ✓

Observability ? ✓

Page 48: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Extensibility

@junr03

Using protobuf annotations to declare API behavior

Page 49: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

service Foo {

rpc GetFoo(FooRequest) returns (FooResponse) {

option (http.http_options).path = "/foo/receive";

option (http.http_options).method = "GET";

option (http.http_options).client_poll_ms = 5000;

option (http.http_options).gzip_enabled = true;

}

}

Declarative APIs

@rebello95 @junr03

Page 50: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Service

Envoy

URLSession

iOS

OkHTTP

Android

@rebello95

Page 51: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product flows a fraction of the time.

What do we want from our Client APIs?

@junr03

Consistency ✓ ✓

Performance ✓ ✓

Extensibility 🤔 ? ✓

Resilience ? ✓

Security ? ✓

Observability ? ✓

Page 52: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

We recognized two important dimensions in API management: what data we send (shape), and how we send it (transport).

@junr03

API Transport

Page 53: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Service

Envoy

Library X

Client

@rebello95

Page 54: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Clients as another node in the mesh

Storage

Edge

Sidecar

Service B

Sidecar

Service A

3rd-partyClient

@goaway @junr03

Page 55: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Standardizing infrastructure

@goaway @junr03

Page 56: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Why is world domination transport standardization useful?

● Write once, deploy everywhere

● Common tooling for common problems

● Reduce cognitive load

@goaway @junr03

Page 57: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Envoy Mobile to the rescue!

● v0.1: proof-of-concept

● v0.2: laying the foundation

● v0.3: first production-ready release

@goaway @junr03

Page 58: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Envoy as a Library

@junr03

How did we turn a network proxy into a networking library?

Page 59: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Build System: bazel

@goaway @junr03

● Cross-platform support

● Used by Envoy

Page 60: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

//library/common:c_types//library/kotlin:android_framework

//library/swift:ios_framework

Layered Architecture

//:ios_dist

//:android_dist

//library/common:main_interface

@goaway @junr03

//library/common/...

@envoy//source/...

Platform (iOS/Android) Bridge (C) Native (C++/Envoy)

Page 61: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

How to run a process in an app?

picture of an engine (a very fast one)

@goaway @junr03

Page 62: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Threading contexts

Application Threads

Envoy Main Thread

Callback Threads

@goaway @junr03

Page 63: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Library Matrix

Platform (iOS/Android) Bridge (C types/bindings) Native (C++/Envoy)

Application Threads

Envoy Main Thread

Callback Threads

@goaway @junr03

Page 64: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Library Lifecycle - Running Envoy

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

@goaway @junr03

Platform (iOS/Android) Bridge (C types/bindings) Native (C++/Envoy)

Page 65: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Library Lifecycle - Running Envoy

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

EnvoyRunner Engine

@goaway @junr03

Platform (iOS/Android) Bridge (C types/bindings) Native (C++/Envoy)

Page 66: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Server Envoy

Envoy Main Thread

Worker Threads

Envoy

Dispatcher

Http Manager

Requests

@goaway @junr03

Page 67: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Platform (iOS/Android)

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

EnvoyRunner

Dispatcher

Http Manager

@goaway @junr03

Bridge (C types/bindings) Native (C++/Envoy)

Library Lifecycle - using Envoy Constructs

Page 68: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Platform (iOS/Android)

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

EnvoyRunner

Dispatcher

Http Manager

HttpStream

@goaway @junr03

Bridge (C types/bindings) Native (C++/Envoy)

Library Lifecycle - starting a stream

Page 69: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Library Lifecycle - dispatching a stream

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

EnvoyRunner

Dispatcher

Http Manager

HttpStream

@goaway @junr03

Platform (iOS/Android) Bridge (C types/bindings) Native (C++/Envoy)

Page 70: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Http Manager

Http Filters

@junr03

L7 FilterL7 FilterHttp Filter

Dispatcher ● Foundational extension point

● Enact behavior

● Provide the guarantees we want!

Page 71: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Callbacks

Library Lifecycle - callbacks

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

EnvoyRunner

Dispatcher

Http Manager

HttpStream

@goaway @junr03

Platform (iOS/Android) Bridge (C types/bindings) Native (C++/Envoy)

Page 72: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Library Lifecycle - platform callbacks

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

EnvoyRunner

Dispatcher

Http Manager

HttpStream

Callbacks

Lambdas

Dispatcher

@goaway @junr03

Platform (iOS/Android) Bridge (C types/bindings) Native (C++/Envoy)

Page 73: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Platform (iOS/Android)

Overall View

Application Threads

Envoy Main Thread

Callback Threads

EnvoyEngine

EnvoyRunner

Dispatcher

Http Manager

HttpStream

Callbacks

Lambdas

Dispatcher

Canceled

@goaway @junr03

Bridge (C types/bindings) Native (C++/Envoy)

Canceled

Page 74: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Platform Code

let envoy = try EnvoyClientBuilder(domain: "api.envoyproxy.io") .addLogLevel(.warn) .addStatsFlushSeconds(60) .build()

val envoy = EnvoyClientBuilder( Domain("api.envoyproxy.io")) .addLogLevel(LogLevel.WARN) .addStatsFlushSeconds(60) ... .build()

@goaway @junr03

Page 75: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Build an Engine

let envoy = try EnvoyClientBuilder(domain: "api.envoyproxy.io") .addLogLevel(.warn) .addStatsFlushSeconds(60) .build()

@goaway @junr03

Page 76: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Build an Engine

let envoy = try EnvoyClientBuilder(domain: "api.envoyproxy.io") .addLogLevel(.warn) .addStatsFlushSeconds(60) .build()

@goaway @junr03

Page 77: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Build a Request

let request = RequestBuilder(path: "/pb.api.v1.Foo/GetBar") .addHeader(name: "x-custom-header", value: "foobar") .build()

@goaway @junr03

Page 78: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Build a Request

let request = RequestBuilder(path: "/pb.api.v1.Foo/GetBar") .addHeader(name: "x-custom-header", value: "foobar") .build()

@goaway @junr03

Page 79: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Build a Response Handler

let handler = ResponseHandler() .onHeaders { headers, status, _ -> ... } .onData { data -> // Deserialize message data here } ...

@goaway @junr03

Page 80: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Build a Response Handler

let handler = ResponseHandler() .onHeaders { headers, status, _ -> // Product logic } .onData { data -> // Product logic } ...

@goaway @junr03

Page 81: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product flows a fraction of the time.

What do we want from our Client APIs?

@junr03

Consistency ✓ ✓

Performance ✓ ✓

Extensibility 🤔 ? ✓

Resilience ? ✓

Security ? ✓

Observability ? ✓

Page 82: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

IDL pipeline

/api/v1/foo.proto

Generators

+7 others

foo.go

foo.py

foo.kt

foo.swift FooV1API library

foo-v1-api library

@goaway @junr03

NSUrl

OkHttp

Page 83: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

IDL pipeline

/api/v1/foo.proto

Generators

+7 others

foo.go

foo.py

foo.kt

foo.swift FooV1API library

foo-v1-api library

Client

@goaway @junr03

Page 84: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Ecosystem

@junr03

Shape + Transport = Ecosystem!

Page 85: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product flows a fraction of the time.

What do we want from our Client APIs?

Consistency ✓ ✓

Performance ✓ ✓

Extensibility ? ✓

Resilience ? ✓

Security ? ✓

Observability ? ✓@junr03

Page 86: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Extensibility

@junr03

Using protobuf annotations to declare API behavior and Envoy Mobile to enact consistent behavior.

Page 87: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

service Foo {

rpc GetFoo(FooRequest) returns (FooResponse) {

option (http.http_options).path = "/foo/receive";

option (http.http_options).method = "GET";

option (http.http_options).client_poll_ms = 5000;

option (http.http_options).gzip_enabled = true;

}

}

Declarative APIs

@rebello95

Page 88: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Service

Envoy

URLSession

iOS

OkHTTP

Android

@rebello95 @junr03

�� ����

Page 89: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Extensibility

@junr03

Using protobuf annotations to declare API behavior and Envoy Mobile to enact consistent behavior.

Page 90: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Http Manager

Http Filters

@junr03

L7 FilterL7 FilterHttp Filter

Dispatcher ● Foundational extension point

● Enact behavior

● Provide the guarantees we want!

Page 91: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Envoy filters

Compression Filtergzip request

Mobile

Proxy

Compression FilterUnzip payload

🥳

EdgeClient

@junr03

Page 92: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Advanced transport

@junr03

● Dynamic Forward Proxy ✅

● Compression 🚧

● Deferred Requests 🕒 (Resilience)

● OAuth 🕒 (Security)

● Request Signing 🕒 (Security)

● Network condition 🕒 (Resilience)

Page 93: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Deferred Requests

@junr03

Deferred Request Filter

Mobile

Proxy

Client❌ Service ❌

Deferred Request Filter

Mobile

Proxy

Client✅ Service ✅

🥳

��

��

Page 94: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Request Signing

@junr03

Client

Request Signature Filter

sign request

Mobile

Proxy

Request Signature Filter

Verify signature

Edge

🕵‍♀

Page 95: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Advanced transport

@junr03

● Dynamic Forward Proxy ✅

● Compression 🚧

● Deferred Requests 🕒 (Resilience)

● OAuth 🕒 (Security)

● Request Signing 🕒 (Security)

● Network condition 🕒 (Resilience)

Page 96: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Observability

@junr03

True end-to-end insight

Page 97: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Observability

ts(envoy_mobile.cluster.api.upstream_rq.count)

ts(envoy_edge.cluster.*.upstream_rq.count)

@goaway @junr03

Page 98: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Time-series Metrics

MetricsService

@goaway @junr03

Page 99: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Dashboards!

ts(envoy_edge...)

@goaway @junr03

ts(envoy_mobile...)

Page 100: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product flows a fraction of the time.

What do we want from our Client APIs?

@junr03

Consistency ✓ ✓

Extensibility ✓ ✓

Performance ✓ ✓

Resilience ✓ ✓

Security ✓ ✓

Observability ✓ ✓

Page 101: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Onwards!

● Additional functionality in filters

● Protocol Experimentation with QUIC

● OSS Code Generators: complete OSS ecosystem for model-based

APIs.

@junr03

Page 102: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Next Generation Client APIs

@junr03

Model-based APIs defined in a strongly-typed IDL so platform engineers can iterate on behavior using

a common transport layer.

Page 103: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

Alpha Beta Production Experiment @Lyft!

@goaway @junr03

Page 104: Next Generation Client APIs with Envoy Mobile · Three 9s of reliability at the server-side is meaningless if the user of a mobile client is only able to complete the desired product

envoy-mobile.github.io@junr03

Join us!