39
© 2019 TWILIO INC. ALL RIGHTS RESERVED. © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior Principal Engineer & Frontend Architect

Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED. © 2019 TWILIO INC. ALL RIGHTS RESERVED.

Building APIs for Scalable Client-Side Applications Steve Kinney Senior Principal Engineer & Frontend Architect

Page 2: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

An Overly Brief History of

Applications on the Web

From thick-client desktop applications to server-rendered web applications.

From server-rendered web applications to thick-client JavaScript applications.

The rise of mobile, tablets, etc.

Page 3: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Microservices considered harmful.*

Page 4: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

That’s not really fair.

Microservices are great for a number of reasons.

You can reuse services across multiple business needs.

The API of each service creates a well-defined surface area.

¸You can rewrite a single piece of your architecture, if needed.

Each component of your architecture can be deployed separately.

Page 5: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Microservices considered harmful—for client-side applications, sometimes.

Page 6: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

The problem with a lot of technical choices is that reality has a nasty habit

of changing underneath our feet.

Page 7: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Microservices do create some

problems for client applications.

(Don’t worry. We’ll talk about some solutions.)

We've accidentally shifted a lot of complexity over to the frontend applications.

The data we need for a particular view might be split across multiple microservices.

Caching computed data is no longer an option.

The client-side application still has to feel like a cohesive experience—regardless of how many services back it.

Page 8: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 9: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 10: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 11: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 12: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 13: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 14: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

The Cost of JavaScript

Page 15: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

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

Page 16: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 17: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Potential Problems

Too much data

Not enough data

Page 18: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 19: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

One Gateway to Rule Them All?

What are some problems with this current approach?

Different platforms are going to have different needs.

You separate the team who needs an endpoint from the team who can create it.

Breaking changes.

Deployments aren’t free.

Prioritizing the requests from multiple teams can be tricky on an organizational level.

It can get bloated.

Page 20: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Maybe microservices are good after all.

Page 21: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

That’s not really fair.

Microservices are great for a number of reasons.

You can reuse services across multiple business needs.

The API of each service creates a well-defined surface area.

¸You can rewrite a single piece of your architecture, if needed.

Each component of your architecture can be deployed separately.

Page 22: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 23: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

What about duplicated logic?

(Because that’s not already happening in your organization, right?)

You can break things out into shared libraries.

You can abstract out additional services.

Does that logic belong in your middle tier at all?

Each component of your architecture can be deployed separately.

Page 24: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 25: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Guidance

As much as you need and as little as you can get away with.

Use technologies that support non-blocking or concurrent technologies.

Page 26: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

{

"posts": [

{

"id": "1",

"title": "A Very First Post",

"content": {

"href": "/posts/1/content"

}

},

{

"id": "2",

"title": "An Apology for the First Post",

"content": {

"href": "/posts/2/content"

}

}

]

}

Page 27: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

{

"posts": [

{

"id": "1",

"title": "A Very First Post",

"content": "We're excited to announce…"

},

{

"id": "2",

"title": "An Apology for the First Post",

"content": "It has come to our attention…"

}

]

}

Page 28: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 29: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Benefits of an Adapter Layer

Changing API contracts.

Breaking out additional services.

Stubbing out data for new features.

Page 30: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Graduate-level Advantages

Server-side rendering.

Caching for shared data.

Page 31: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 32: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

206 Partial Content

503 Service Unavailable

What if things go wrong?

Page 33: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 34: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

Page 35: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

query {

posts {

title

author

summary

}

}

Page 36: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

query {

posts {

title

author

}

}

Page 37: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

What are the trade-offs that you need to consider?

Page 38: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

© 2019 TWILIO INC. ALL RIGHTS RESERVED.

In conclusion…

Page 39: Building APIs for Scalable Client-Side Applications · 2019-10-28 · © 2019 TWILIO INC. ALL RIGHTS RESERVED. Building APIs for Scalable Client-Side Applications Steve Kinney Senior

THANK YOU