building apis for scalable client-side applications · 2019-10-28 · © 2019 twilio inc. all...
TRANSCRIPT
© 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
© 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.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
Microservices considered harmful.*
© 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.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
Microservices considered harmful—for client-side applications, sometimes.
© 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.
© 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.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
The Cost of JavaScript
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
https://samnewman.io/patterns/architectural/bff
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
Potential Problems
Too much data
Not enough data
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 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.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
Maybe microservices are good after all.
© 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.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 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.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 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.
© 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"
}
}
]
}
© 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…"
}
]
}
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
Benefits of an Adapter Layer
Changing API contracts.
Breaking out additional services.
Stubbing out data for new features.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
Graduate-level Advantages
Server-side rendering.
Caching for shared data.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
206 Partial Content
503 Service Unavailable
What if things go wrong?
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
query {
posts {
title
author
summary
}
}
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
query {
posts {
title
author
}
}
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
What are the trade-offs that you need to consider?
© 2019 TWILIO INC. ALL RIGHTS RESERVED.
In conclusion…
THANK YOU