Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr...

27
Web Services Mash-up : Flickr Cal Henderson <[email protected]> O’Reilly Emerging Technology Conference March 14-17, 2005

Transcript of Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr...

Page 1: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Web Services Mash-up : Flickr

Cal Henderson <[email protected]>

O’Reilly Emerging Technology ConferenceMarch 14-17, 2005

Page 2: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

What’s Flickr?

• A website – flickr.com• A photo-sharing application• The centre of a big distributed system• An open set of APIs

– flickr.com/services/

Page 3: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

‘Traditional’ Photo Sites

Photos-of-Kittens.com

Original Photos Prints

Low-res viewing

Page 4: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Flickr

www.flickr.com

Original Photos Prints

Low-res viewingHi-res downloads

More Stuff

More Stuff

Page 5: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

More stuff ?

• But how do we get more stuff into the system

• And how do we get it out?• And what ‘stuff’ do we want to be able

to get in and out?

Page 6: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Yes, More Stuff

• We want everything!• We don’t yet know what’s great...

– People can use data in all sorts of cool ways that you never thought of

– And people can send you data in cool ways too

Page 7: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Web services to the rescue

• But what use are web services?• The future of the Interwebnet!!!1• A technology which enables geeks to

interface with your software

Page 8: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

What’s this about a new way?

• Flickr has a bunch of ‘web services’• RSS/Atom/RDF feeds output data in

nice reusable ways• The Flickr API lets people get data in

and out of Flickr however they like

Page 9: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Logical Architecture

Page Logic

Business/Application Logic

DatabasePhoto Storage

API Logic

EndpointsTemplates

Users

3rd Party Apps Flickr Apps

Node Service

Flickr.comEmail

Parser

Page 10: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Logical Architecture

Page Logic

Business/Application Logic

DatabasePhoto Storage

API Logic

EndpointsTemplates

Users

3rd Party Apps Flickr Apps

Node Service

Flickr.comEmail

Parser

Page 11: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

API Architecture

Endpoints

Users

Applications

HTTP Transport

Net / Local Transport

Page 12: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Protocol Voodoo

• Like any decent Internet ‘standard’, there’s more than one

• A quick guide to the trendy ones flickr supports…

Page 13: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

SOAP

• Simple Object Access Protocol• Now just SOAP

– (not so simple anymore)

• Google uses it

Page 14: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

SOAP Response

<s:Envelope xmlns:s=“http://www.w3.org/2003/05/soap-envelope” xmlns:xsi=“http://www.w3.org/1999/XMLSchema-instance” xmlns:xsd=“http://www.w3.org/1999/XMLSchema”> <s:Body> <x:FlickrResponse xmlns:x="urn:flickr"> [escaped-xml-payload] </x:FlickrResponse> </s:Body></s:Envelope>

Page 15: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

XML-RPC

• XML Remote Procedure Call• Used by the blogging APIs• Created by Dave Winer in 1998

– Because SOAP was taking a long time

Page 16: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

XML-RPC Response

<methodResponse> <params> <param> <value> <string> [escaped-xml-payload] </string> </value> </param> </params></methodResponse>

Page 17: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

REST

• Representational State Transfer– Crazy name

• Thanks Roy Fielding at Apache

• It’s really simple– Just XML over HTTP– (Though purists say it’s only HTTP GET)

Page 18: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

REST Response

<rsp stat="ok"> [xml-payload]</rsp>

Page 19: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Page Scraping

• Been around for ever• HTML-over-HTTP• Volatile interface• Makes site owners angry• Other protocols are for sissies

(possibly)

Page 20: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Offering Web Services

• Be transport agnostic– Some people love SOAP, some love REST– Make them all (somewhat) happy

• Beware of ‘shitty coders’

Page 21: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Performance Problems

• People can scrape your site and pull a lot of pages in a short time

• This is bad• But API abuse (even accidental) can be

a lot worse

Page 22: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

An example

• Someone writes a trendy screensaver app for Flickr which shows recent photos

• It checks for new photos every 2 seconds

• A bunch of people download it

Page 23: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Danger!

• With 100 users, that’s 50 hits per second (about 4.3 million in a day)

• If it’s making a particularly taxing database call, it’s going to cause problems

Page 24: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Possible solutions

• Incorporate caching into API bindings• Enforce a policy

– Through API keys, etc.

• Cache at the host application level• Monitor things closely

Page 25: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

Authentication

• Authentication parameters as request parameters– ?username=cal&password=kittens

• HTTP Basic Auth• HTTPS• WSSE

Page 26: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage

What we have learned

• Be open• Be protocol agnostic• Be careful of abuse• Be nice

Page 27: Web Services Mash-up : Flickr · • The Flickr API lets people get data in and out of Flickr however they like. Logical Architecture Page Logic Business/Application Logic Photo Storage