49
API Design: When to buck the trend Netflix API case study with Daniel Jacobson Daniel Jacobson Netflix @daniel_jacobson groups.google.com/group/ api-craft Greg Brail Apigee @gbrail

API Design - When to buck the trend (Webcast)

  • Upload
    apigee

  • View
    8.880

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: API Design - When to buck the trend (Webcast)

API Design: When to buck the trend

Netflix API case study with Daniel Jacobson

Daniel JacobsonNetflix@daniel_jacobson

groups.google.com/group/api-craft

Greg BrailApigee@gbrail

Page 2: API Design - When to buck the trend (Webcast)

groups.google.com/group/api-craft

Page 3: API Design - When to buck the trend (Webcast)

youtube.com/apigee

Page 4: API Design - When to buck the trend (Webcast)

slideshare.net/apigee

Page 5: API Design - When to buck the trend (Webcast)

http://tinyurl.com/api-strategy-book

Page 6: API Design - When to buck the trend (Webcast)

@daniel_jacobsonDaniel Jacobson

@gbrailGreg Brail

Page 7: API Design - When to buck the trend (Webcast)

Pragmatic REST style

One size fits all

JSON

OAuth

API versioning in the URI

What’s the trend?

Page 8: API Design - When to buck the trend (Webcast)

Trend:PRAGMATIC REST

Page 9: API Design - When to buck the trend (Webcast)

URIs are carefully designed

Each URI represents a “resource”

Resource actions are defined by HTTP verbs

GET (read), POST (create), PUT (update), DELETE

Pragmatic REST – most common style today

Page 10: API Design - When to buck the trend (Webcast)

Pure REST

Ad-hoc XML / JSON over HTTP

SOAP

Pragmatic REST alternatives

Page 11: API Design - When to buck the trend (Webcast)

Quick definition:

A REST API as defined by Roy Fieldinghttp://en.wikipedia.org/wiki/RESTand followershttp://martinfowler.com/articles/richardsonMaturityModel.html

Alternative: pure REST

Page 12: API Design - When to buck the trend (Webcast)

Flexible, powerful, and evolvable over decades…

Slow, hard to program, and rare

Alternative: pure REST

Page 13: API Design - When to buck the trend (Webcast)

Most APIs that call themselves “REST” are not actually REST by the pure definition

So pure REST APIs buck the trend. Why?The server implementation can change URIsThe URI structure is not documented – clients follow linksSo, the server implementation can change the whole structure of the API

In theory, the API can evolve forever without ever being “incompatible”

So who cares about REST?

Page 14: API Design - When to buck the trend (Webcast)

Trend:ONE SIZE FITS ALL

Page 15: API Design - When to buck the trend (Webcast)

Does it make sense to have the same API for all developers?

One size fits all

Page 16: API Design - When to buck the trend (Webcast)

API team can focus on one precise, well-documented API

Reduce training costs across development teams

Can support an unlimited number of known and unknown developers

One size fits all – why yes?

Page 17: API Design - When to buck the trend (Webcast)

Treats all clients generically, so optimized for none

API team becomes bottleneck for UI development

One size fits all – why not?

Page 18: API Design - When to buck the trend (Webcast)
Page 19: API Design - When to buck the trend (Webcast)

Some of the many client differences:

Memory capacity

Distinct markup types (XML, JSON)

Flat vs. Hierarchical document models

Screen real estate

Document delivery

User interaction models

One size fits all – why not?

Page 20: API Design - When to buck the trend (Webcast)
Page 21: API Design - When to buck the trend (Webcast)
Page 22: API Design - When to buck the trend (Webcast)

Small number of targeted API consumers is the top priority

Very close relationships between these API consumers and the API team

Increasing divergence of needs across the top priority API consumers

Strong desire by the API consumers for more optimized interactions with the API

High value proposition for the API provider to make these API consumers as effective as possible

How do you know if your company is ready to consider alternatives to the one-size-fits-all API model?

Page 23: API Design - When to buck the trend (Webcast)

Embrace the differences of the devices

Separate content gathering from content formatting and delivery

Redefine the border between client and server

Distribute innovation

Netflix’s approach against one-size-fits-all API

Page 24: API Design - When to buck the trend (Webcast)

REST API

RECOMMENDATIONS

MOVIE DATA

SIMILAR MOVIES

AUTH MEMBERDATA

A/B TESTS

START-UP

RATINGS

Network Border Network Border

Netflix REST API Model

Page 25: API Design - When to buck the trend (Webcast)

JAVA API

Network Border Network Border

RECOMMENDATIONS

MOVIE DATA

SIMILAR MOVIES

AUTH MEMBERDATA

A/B TESTS

START-UP

RATINGS

Netflix New Non-REST API Model

Page 26: API Design - When to buck the trend (Webcast)

RECOMMENDATIONS

MOVIE DATA

SIMILAR MOVIES

AUTH MEMBERDATA

A/B TESTS

START-UP

RATINGS

REST API

Network Border Network Border

SERVER CODE

CLIENT CODE

Netflix REST API Model

Page 27: API Design - When to buck the trend (Webcast)

RECOMMENDATIONSA

ZXSXX C CCC

MOVIE DATA

SIMILAR MOVIES

AUTH MEMBERDATA

A/B TESTS

START-UP

RATINGS

JAVA API

SERVER CODE

CLIENT CODE

CLIENT ADAPTER CODE(ON SERVER)

Network Border Network Border

Netflix New Non-REST API Model

Page 28: API Design - When to buck the trend (Webcast)

Why not have both?

Layer the different APIs over a common API

One size fits all – other alternatives

Page 29: API Design - When to buck the trend (Webcast)

One size fits all – other alternatives

Page 30: API Design - When to buck the trend (Webcast)

Other alternatives provide greater flexibility but still have server teams dictate rules

Doesn’t alleviate server team bottleneck issue

One size fits all – other alternatives

Page 31: API Design - When to buck the trend (Webcast)

Trend:JSON

Page 32: API Design - When to buck the trend (Webcast)
Page 33: API Design - When to buck the trend (Webcast)

JSON and XML are exactly the same

JSON is always smaller than XML

JSON is always faster to parse than XML

All clients can parse JSON

All servers can produce JSON

JSON Conventional Wisdom

Page 34: API Design - When to buck the trend (Webcast)

Not all devices support JSON out of the box

Different devices may require different XML schemas

Some devices prefer full document delivery and others prefer streaming bits

XML and JSON aren’t all that different in size once you compress them

XML has a different data model than JSON

JSON considerations

Page 35: API Design - When to buck the trend (Webcast)

There are many more tools built around XML today than there are built around JSON

XML offers more semantic context than JSON

Saying XML or JSON is not enough – both can support very different document models

More JSON considerations

Page 36: API Design - When to buck the trend (Webcast)

Design the guts of the API to separate data gathering from data formatting

Add a mediation layer (in your code our outside) to render the right format

If in doubt, support JSON internally, and support conversion to other formats as a wrapper

JSON -> XML is easier than XML -> JSON

JSON advice

Page 37: API Design - When to buck the trend (Webcast)

Trend:OAUTH

Page 38: API Design - When to buck the trend (Webcast)

Essential for

APIs that authenticate end users

Unknown (to you) developers

Mobile and native clients

OAuth – super-big trend in APIs

Page 39: API Design - When to buck the trend (Webcast)

Cookies

Netflix’s new approach

Great for apps that are based on browsers

Great if API consumers are very close to API team

OAuth alternatives

Page 40: API Design - When to buck the trend (Webcast)

HTTP Basic Auth + SSLTwo-way SSL

Both are great for server-to-server APIs

OAuth alternatives

Page 41: API Design - When to buck the trend (Webcast)

API keys only

“Two-legged” access when there is no “user”

OAuth alternatives

Page 42: API Design - When to buck the trend (Webcast)

Trend:API VERSIONING IN URI

Page 43: API Design - When to buck the trend (Webcast)

Many APIs include a version number in theURI (like api.foo.com/v1)Hostname (v1.api.foo.com)Query parameter (api.foo.com/v1/bar?version=1)Content-type header

The version number represents the interface version

The number changes, although rarely

Versioning

Page 44: API Design - When to buck the trend (Webcast)

If you can achieve it, maintenance will be MUCH simpler

If you cannot, it instills better practicesReduces lazy programmingResults in fewer versionsResults in a cleaner, less brittle system

And keep in mind, adding new features typically does not require a new version…

Schematic or structural changes, however, do

Can an API call have NO version?

Page 45: API Design - When to buck the trend (Webcast)

Average life of a TV: 7-10 years

Page 46: API Design - When to buck the trend (Webcast)

1.0

1.5

2.0

Today

3.0?

4.0?

5.0?

2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020

Versioning

Page 47: API Design - When to buck the trend (Webcast)

1.0

1.5

2.0

New API

Today

2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020

Versioning

Page 48: API Design - When to buck the trend (Webcast)

groups.google.com/group/api-craft

Page 49: API Design - When to buck the trend (Webcast)

THANK YOUQuestions and ideas to:

@gbrail @daniel_jacobson

groups.google.com/group/api-craft