SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
Flickr and PHP
   Cal Henderson
What’s Flickr

• Photo sharing
• Open APIs
Logical Architecture

     Photo Storage                 Database          Node Service


                     Application Logic


               Page Logic                     API


                Templates                Endpoints


                                 3rd Party Apps      Flickr Apps
              Flickr.com
  Email




                               Users
Physical Architecture

   Static Servers   Database Servers   Node Servers




                     Web Servers



                        Users
Where is PHP?

     Photo Storage                Database           Node Service


                     Application Logic


               Page Logic                    API


                Templates                Endpoints


                                 3rd Party Apps      Flickr Apps
              Flickr.com
  Email




                               Users
Other than PHP?

•   Smarty for templating
•   PEAR for XML and Email parsing
•   Perl for controlling…
•   ImageMagick, for image processing
•   MySQL (4.0 / InnoDb)
•   Java, for the node service
•   Apache 2, Redhat, etc. etc.
Big Application?

•   One programmer, one designer, etc.
•   ~60,000 lines of PHP code
•   ~60,000 lines of templates
•   ~70 custom smarty functions/modifiers
•   ~25,000 DB transactions/second at peak
•   ~1000 pages per second at peak
Thinking outside the web app

• Services
   – Atom/RSS/RDF Feeds
   – APIs
      •   SOAP
      •   XML-RPC
      •   REST
      •   PEAR::XML::Tree
More cool stuff

• Email interface
    – Postfix
    – PHP
    – PEAR::Mail::mimeDecode
•   FTP
•   Uploading API
•   Authentication API
•   Unicode
Even more stuff

• Real time application
• Cool flash apps
• Blogging
   –   Blogger API (1 & 2)
   –   Metaweblog API
   –   Atom
   –   LiveJournal
APIs are simple!

•   Modeled on XML-RPC (Sort of)
•   Method calls with XML responses
•   SOAP, XML-RPC and REST are just transports
•   PHP endpoints mean we can use the same application
    logic as the website
XML isn’t simple :(

• PHP 4 doesn’t have good a XML parser
• Expat is cool though (PEAR::XML::Parser)
• Why doesn’t PEAR have XPath?
   – Because PEAR is stupid!
   – PHP 4 sucks!
I love XPath

if ($tree->root->name == 'methodResponse'){
      if (($tree->root->children[0]->name == 'params')
       && ($tree->root->children[0]->children[0]->name == 'param')
       && ($tree->root->children[0]->children[0]->children[0]->name == 'value')
       && ($tree->root->children[0]->children[0]->children[0]->children[0]->name == 'array')
       && ($tree->root->children[0]->children[0]->children[0]->children[0]->children[0]->name == 'data')){
               $rsp = $tree->root->children[0]->children[0]->children[0]->children[0]->children[0];
      }
      if ($tree->root->children[0]->name == 'fault'){
               $fault = $tree->root->children[0];
               return $fault;
      }
}




$nodes = $tree->select_nodes('/methodResponse/params/param[1]/value[1]/array[1]/data[1]/text()');

if (count($nodes)){
      $rsp = array_pop($nodes);
}else{
      list($fault) = $tree->select_nodes('/methodResponse/fault');
      return $fault;
}
Creating API methods

• Stateless method-call APIs are easy to extend
• Adding a method requires no knowledge of the transport
• Adding a method once makes it available to all the
  interfaces
• Self documenting
Red Hot Unicode Action

• UTF-8 pages
• CJKV support
• It’s really cool
Unicode for all

• It’s really easy
   –   Don’t need PHP support
   –   Don’t need MySQL support
   –   Just need the right headers
   –   UTF-8 is 7-bit transparent
   –   (Just don’t mess with high characters)
        • Don’t use HtmlEntities()!
• But bear in mind…
        • JavaScript has patchy Unicode support
        • People using your APIs might be stupid
Scaling the beast

•   Why PHP is great
•   MySQL scaling
•   Search scaling
•   Horizontal scaling
Why PHP is great

• Stateless
   –   We can bounce people around servers
   –   Everything is stored in the database
   –   Even the smarty cache
   –   “Shared nothing”
   –   (so long as we avoid PHP sessions)
MySQL Scaling

• Our database server started to slow
• Load of 200
• Replication!
MySQL Replication

• But it only gives you more SELECT’s
• Else you need to partition vertically
• Re-architecting sucks :(
Looking at usage

• Snapshot of db1.flickr.com
   –   SELECT’s 44,220,588
   –   INSERT’s 1,349,234
   –   UPDATE’s 1,755,503
   –   DELETE’s 318,439
   –   13 SELECT’s per I/U/D
Replication is really cool

• A bunch of slave servers handle all the SELECT’s
• A single master just handles I/U/D’s
• It can scale horizontally, at least for a while.
Searching

•   A simple text search
•   We were using RLIKE
•   Then switched to LIKE
•   Then disabled it all together
FULLTEXT Indexes

•   MySQL saves the day!
•   But they’re only supported my MyISAM tables
•   We use InnoDb, because it’s a lot faster
•   We’re doomed
But wait!

• Partial replication saves the day
• Replicate the portion of the database we want to search.
• But change the table types on the slave to MyISAM
• It can keep up because it’s only handling I/U/D’s on a
  couple of tables
• And we can reduce the I/U/D’s with a little bit of vertical
  partitioning
JOIN’s are slow

•   Normalised data is for sissies
•   Keep multiple copies of data around
•   Makes searching faster
•   Have to ensure consistency in the application logic
Our current setup


                         DB1
                                  I/U/D’s
                         Master




          SELECT’s
                         DB2
                     Main Slave




                                            DB3
                                       Main Search
            Slave Farm
                                          slave
                                                      Search
                                                     SELECT’s


                                     Search Slave
                                        Farm
Horizontal scaling

•   At the core of our design
•   Just add hardware!
•   Inexpensive
•   Not exponential
•   Avoid redesigns
Talking to the Node Service

• Everyone speaks XML (badly)
• Just TCP/IP - fsockopen()
• We’re issuing commands, not requesting data, so we
  don’t bother to parse the response
   – Just substring search for state=“ok”
• Don’t rely on it!
RSS / Atom / RDF

•   Different formats
•   All quite bad
•   We’re generating a lot of different feeds
•   Abstract the difference away using templates
•   No good way to do private feeds. Why is nobody working
    on this? (WSSE maybe?)
Receiving email

•   Want users to be able to email photos to Flickr
•   Just get postfix to pipe each mail to a PHP script
•   Parse the mail and find any photos
•   Cellular phone companies hate you
•   Lots of mailers are retarded
    – Photos as text/plain attachments :/
Upload via FTP

• PHP isn’t so great at being a daemon
• Leaks memory like a sieve
• No threads
• Java to the rescue
• Java just acts as an FTPd and passes all uploaded files
  to PHP for processing
• (This isn’t actually public)
• Bricolage does this I think. Maybe Zope?
Blogs

• Why does everyone loves blogs so much?
• Only a few APIs really
   –   Blogger
   –   Metaweblog
   –   Blogger2
   –   Movable Type
   –   Atom
   –   Live Journal
It’s all broken

•   Lots of blog software has broken interfaces
•   It’s a support nightmare
•   Manila is tricky
•   But it all works, more or less
•   Abstracted in the application logic
•   We just call blogs_post_message();
Back to those APIs

• We opened up the Flickr APIs a few weeks ago
• Programmers mainly build tools for other programmers
• We have Perl, python, PHP, ActionScript, XMLHTTP and
  .NET interface libraries
• But also a few actual applications
Flickr Rainbow
Tag Wallpaper
So what next?

•   Much more scaling
•   PHP 5?
•   MySQL 5?
•   Taking over the world
Flickr and PHP
   Cal Henderson
Any Questions?

Contenu connexe

Tendances

Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQLAmazon Web Services
 
Mobile iOS Application Architectures
Mobile iOS Application ArchitecturesMobile iOS Application Architectures
Mobile iOS Application ArchitecturesArpit Kulsreshtha
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practicesAnkita Mahajan
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL Josh Price
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentationVibhor Grover
 
REST and RESTful Web Services
REST and RESTful Web ServicesREST and RESTful Web Services
REST and RESTful Web ServicesKasun Madusanke
 
Ontology Mapping
Ontology MappingOntology Mapping
Ontology Mappingbutest
 
SAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID ConnectSAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID ConnectUbisecure
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 
Swagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdfSwagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdfKnoldus Inc.
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In DepthFabio Fumarola
 

Tendances (20)

Restful api
Restful apiRestful api
Restful api
 
Building Modern APIs with GraphQL
Building Modern APIs with GraphQLBuilding Modern APIs with GraphQL
Building Modern APIs with GraphQL
 
Mobile iOS Application Architectures
Mobile iOS Application ArchitecturesMobile iOS Application Architectures
Mobile iOS Application Architectures
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
Testing Spring Applications
Testing Spring ApplicationsTesting Spring Applications
Testing Spring Applications
 
Better APIs with GraphQL
Better APIs with GraphQL Better APIs with GraphQL
Better APIs with GraphQL
 
Graphql presentation
Graphql presentationGraphql presentation
Graphql presentation
 
REST and RESTful Web Services
REST and RESTful Web ServicesREST and RESTful Web Services
REST and RESTful Web Services
 
Ontology Mapping
Ontology MappingOntology Mapping
Ontology Mapping
 
SAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID ConnectSAML VS OAuth 2.0 VS OpenID Connect
SAML VS OAuth 2.0 VS OpenID Connect
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Jpa
JpaJpa
Jpa
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
Rest API
Rest APIRest API
Rest API
 
SOA Principles : 3.service discoverability
SOA Principles : 3.service discoverabilitySOA Principles : 3.service discoverability
SOA Principles : 3.service discoverability
 
Database ms priyanka
Database ms priyankaDatabase ms priyanka
Database ms priyanka
 
SOA Principles : 5. service abstraction
SOA Principles : 5. service abstractionSOA Principles : 5. service abstraction
SOA Principles : 5. service abstraction
 
An Introduction To REST API
An Introduction To REST APIAn Introduction To REST API
An Introduction To REST API
 
Swagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdfSwagger With REST APIs.pptx.pdf
Swagger With REST APIs.pptx.pdf
 
7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth7. Key-Value Databases: In Depth
7. Key-Value Databases: In Depth
 

Similaire à Flickr Architecture Presentation

Flickr Architecture Presentation
Flickr Architecture PresentationFlickr Architecture Presentation
Flickr Architecture Presentationweb25
 
flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php coolpics
 
Flickr Php
Flickr PhpFlickr Php
Flickr Phproyans
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Servicesroyans
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Servicesroyans
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMatt Butcher
 
Facebook architecture
Facebook architectureFacebook architecture
Facebook architecturedrewz lin
 
Facebook architecture
Facebook architectureFacebook architecture
Facebook architecturemysqlops
 
Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01jgregory1234
 
Facebook的架构
Facebook的架构Facebook的架构
Facebook的架构yiditushe
 
Profiling php applications
Profiling php applicationsProfiling php applications
Profiling php applicationsJustin Carmony
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Clusterguestd34230
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & ScalabilityJoseph Scott
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorialoscon2007
 
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
Lennart Regebro   What Zope Did Wrong (And What To Do Instead)Lennart Regebro   What Zope Did Wrong (And What To Do Instead)
Lennart Regebro What Zope Did Wrong (And What To Do Instead)Vincenzo Barone
 
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
Lennart Regebro   What Zope Did Wrong (And What To Do Instead)Lennart Regebro   What Zope Did Wrong (And What To Do Instead)
Lennart Regebro What Zope Did Wrong (And What To Do Instead)Vincenzo Barone
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The EnterpriseMatt Aimonetti
 

Similaire à Flickr Architecture Presentation (20)

Flickr Architecture Presentation
Flickr Architecture PresentationFlickr Architecture Presentation
Flickr Architecture Presentation
 
flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php
 
Flickr Php
Flickr PhpFlickr Php
Flickr Php
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Services
 
Flickr Services
Flickr ServicesFlickr Services
Flickr Services
 
Mashups with Drupal and QueryPath
Mashups with Drupal and QueryPathMashups with Drupal and QueryPath
Mashups with Drupal and QueryPath
 
Facebook architecture
Facebook architectureFacebook architecture
Facebook architecture
 
Facebook architecture
Facebook architectureFacebook architecture
Facebook architecture
 
Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01Qcon 090408233824-phpapp01
Qcon 090408233824-phpapp01
 
Facebook的架构
Facebook的架构Facebook的架构
Facebook的架构
 
Top ten-list
Top ten-listTop ten-list
Top ten-list
 
Qcon
QconQcon
Qcon
 
Profiling php applications
Profiling php applicationsProfiling php applications
Profiling php applications
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 
From One to a Cluster
From One to a ClusterFrom One to a Cluster
From One to a Cluster
 
WordPress Performance & Scalability
WordPress Performance & ScalabilityWordPress Performance & Scalability
WordPress Performance & Scalability
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorial
 
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
Lennart Regebro   What Zope Did Wrong (And What To Do Instead)Lennart Regebro   What Zope Did Wrong (And What To Do Instead)
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
 
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
Lennart Regebro   What Zope Did Wrong (And What To Do Instead)Lennart Regebro   What Zope Did Wrong (And What To Do Instead)
Lennart Regebro What Zope Did Wrong (And What To Do Instead)
 
Merb For The Enterprise
Merb For The EnterpriseMerb For The Enterprise
Merb For The Enterprise
 

Plus de eraz

Mustaches
MustachesMustaches
Mustacheseraz
 
Most Unusual Haircut
Most Unusual HaircutMost Unusual Haircut
Most Unusual Haircuteraz
 
Cool Unusual Sculptures
Cool Unusual SculpturesCool Unusual Sculptures
Cool Unusual Sculptureseraz
 
Funny
FunnyFunny
Funnyeraz
 
Wal Mart Presentation Citigroup 021407
Wal  Mart  Presentation  Citigroup 021407Wal  Mart  Presentation  Citigroup 021407
Wal Mart Presentation Citigroup 021407eraz
 
Top 5 Dos And Don Ts For Measuring Web 2 0
Top 5  Dos And  Don Ts For  Measuring  Web 2 0Top 5  Dos And  Don Ts For  Measuring  Web 2 0
Top 5 Dos And Don Ts For Measuring Web 2 0eraz
 
Wal Mart Presentation Citigroup 021407
Wal Mart Presentation Citigroup 021407Wal Mart Presentation Citigroup 021407
Wal Mart Presentation Citigroup 021407eraz
 
Are Agile Projects Doomed To Halfbaked Design
Are Agile Projects Doomed To Halfbaked DesignAre Agile Projects Doomed To Halfbaked Design
Are Agile Projects Doomed To Halfbaked Designeraz
 
Web Applications Are Getting Interesting!
Web Applications Are Getting Interesting!Web Applications Are Getting Interesting!
Web Applications Are Getting Interesting!eraz
 
Web20 Expo 2007 Mobile Experience
Web20 Expo 2007 Mobile ExperienceWeb20 Expo 2007 Mobile Experience
Web20 Expo 2007 Mobile Experienceeraz
 
Sxsw2007 Mobile
Sxsw2007 MobileSxsw2007 Mobile
Sxsw2007 Mobileeraz
 
Form A Wall Presentation Short
Form A Wall Presentation   ShortForm A Wall Presentation   Short
Form A Wall Presentation Shorteraz
 
Momentum Infocare Corporate Presentation
Momentum Infocare   Corporate PresentationMomentum Infocare   Corporate Presentation
Momentum Infocare Corporate Presentationeraz
 
Mc Kinney Presentation
Mc Kinney PresentationMc Kinney Presentation
Mc Kinney Presentationeraz
 
Srx Product Introduction Power Point Presentation ©Palmetto Equipment
Srx Product Introduction Power Point Presentation ©Palmetto EquipmentSrx Product Introduction Power Point Presentation ©Palmetto Equipment
Srx Product Introduction Power Point Presentation ©Palmetto Equipmenteraz
 
Pitney Bowes 2006 Presentation Martin
Pitney Bowes 2006 Presentation   MartinPitney Bowes 2006 Presentation   Martin
Pitney Bowes 2006 Presentation Martineraz
 
Dot Net Tips And Tricks
Dot Net Tips And TricksDot Net Tips And Tricks
Dot Net Tips And Trickseraz
 
Dot Mobi Mobile Web Developers Guide
Dot Mobi Mobile Web Developers GuideDot Mobi Mobile Web Developers Guide
Dot Mobi Mobile Web Developers Guideeraz
 
Clearspring Widgetsphere
Clearspring WidgetsphereClearspring Widgetsphere
Clearspring Widgetsphereeraz
 
Babson Glavin Presentation Onsite Videos 2007
Babson Glavin Presentation Onsite Videos 2007Babson Glavin Presentation Onsite Videos 2007
Babson Glavin Presentation Onsite Videos 2007eraz
 

Plus de eraz (20)

Mustaches
MustachesMustaches
Mustaches
 
Most Unusual Haircut
Most Unusual HaircutMost Unusual Haircut
Most Unusual Haircut
 
Cool Unusual Sculptures
Cool Unusual SculpturesCool Unusual Sculptures
Cool Unusual Sculptures
 
Funny
FunnyFunny
Funny
 
Wal Mart Presentation Citigroup 021407
Wal  Mart  Presentation  Citigroup 021407Wal  Mart  Presentation  Citigroup 021407
Wal Mart Presentation Citigroup 021407
 
Top 5 Dos And Don Ts For Measuring Web 2 0
Top 5  Dos And  Don Ts For  Measuring  Web 2 0Top 5  Dos And  Don Ts For  Measuring  Web 2 0
Top 5 Dos And Don Ts For Measuring Web 2 0
 
Wal Mart Presentation Citigroup 021407
Wal Mart Presentation Citigroup 021407Wal Mart Presentation Citigroup 021407
Wal Mart Presentation Citigroup 021407
 
Are Agile Projects Doomed To Halfbaked Design
Are Agile Projects Doomed To Halfbaked DesignAre Agile Projects Doomed To Halfbaked Design
Are Agile Projects Doomed To Halfbaked Design
 
Web Applications Are Getting Interesting!
Web Applications Are Getting Interesting!Web Applications Are Getting Interesting!
Web Applications Are Getting Interesting!
 
Web20 Expo 2007 Mobile Experience
Web20 Expo 2007 Mobile ExperienceWeb20 Expo 2007 Mobile Experience
Web20 Expo 2007 Mobile Experience
 
Sxsw2007 Mobile
Sxsw2007 MobileSxsw2007 Mobile
Sxsw2007 Mobile
 
Form A Wall Presentation Short
Form A Wall Presentation   ShortForm A Wall Presentation   Short
Form A Wall Presentation Short
 
Momentum Infocare Corporate Presentation
Momentum Infocare   Corporate PresentationMomentum Infocare   Corporate Presentation
Momentum Infocare Corporate Presentation
 
Mc Kinney Presentation
Mc Kinney PresentationMc Kinney Presentation
Mc Kinney Presentation
 
Srx Product Introduction Power Point Presentation ©Palmetto Equipment
Srx Product Introduction Power Point Presentation ©Palmetto EquipmentSrx Product Introduction Power Point Presentation ©Palmetto Equipment
Srx Product Introduction Power Point Presentation ©Palmetto Equipment
 
Pitney Bowes 2006 Presentation Martin
Pitney Bowes 2006 Presentation   MartinPitney Bowes 2006 Presentation   Martin
Pitney Bowes 2006 Presentation Martin
 
Dot Net Tips And Tricks
Dot Net Tips And TricksDot Net Tips And Tricks
Dot Net Tips And Tricks
 
Dot Mobi Mobile Web Developers Guide
Dot Mobi Mobile Web Developers GuideDot Mobi Mobile Web Developers Guide
Dot Mobi Mobile Web Developers Guide
 
Clearspring Widgetsphere
Clearspring WidgetsphereClearspring Widgetsphere
Clearspring Widgetsphere
 
Babson Glavin Presentation Onsite Videos 2007
Babson Glavin Presentation Onsite Videos 2007Babson Glavin Presentation Onsite Videos 2007
Babson Glavin Presentation Onsite Videos 2007
 

Dernier

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Dernier (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Flickr Architecture Presentation

  • 1. Flickr and PHP Cal Henderson
  • 2. What’s Flickr • Photo sharing • Open APIs
  • 3. Logical Architecture Photo Storage Database Node Service Application Logic Page Logic API Templates Endpoints 3rd Party Apps Flickr Apps Flickr.com Email Users
  • 4. Physical Architecture Static Servers Database Servers Node Servers Web Servers Users
  • 5. Where is PHP? Photo Storage Database Node Service Application Logic Page Logic API Templates Endpoints 3rd Party Apps Flickr Apps Flickr.com Email Users
  • 6. Other than PHP? • Smarty for templating • PEAR for XML and Email parsing • Perl for controlling… • ImageMagick, for image processing • MySQL (4.0 / InnoDb) • Java, for the node service • Apache 2, Redhat, etc. etc.
  • 7. Big Application? • One programmer, one designer, etc. • ~60,000 lines of PHP code • ~60,000 lines of templates • ~70 custom smarty functions/modifiers • ~25,000 DB transactions/second at peak • ~1000 pages per second at peak
  • 8. Thinking outside the web app • Services – Atom/RSS/RDF Feeds – APIs • SOAP • XML-RPC • REST • PEAR::XML::Tree
  • 9. More cool stuff • Email interface – Postfix – PHP – PEAR::Mail::mimeDecode • FTP • Uploading API • Authentication API • Unicode
  • 10. Even more stuff • Real time application • Cool flash apps • Blogging – Blogger API (1 & 2) – Metaweblog API – Atom – LiveJournal
  • 11. APIs are simple! • Modeled on XML-RPC (Sort of) • Method calls with XML responses • SOAP, XML-RPC and REST are just transports • PHP endpoints mean we can use the same application logic as the website
  • 12. XML isn’t simple :( • PHP 4 doesn’t have good a XML parser • Expat is cool though (PEAR::XML::Parser) • Why doesn’t PEAR have XPath? – Because PEAR is stupid! – PHP 4 sucks!
  • 13. I love XPath if ($tree->root->name == 'methodResponse'){ if (($tree->root->children[0]->name == 'params') && ($tree->root->children[0]->children[0]->name == 'param') && ($tree->root->children[0]->children[0]->children[0]->name == 'value') && ($tree->root->children[0]->children[0]->children[0]->children[0]->name == 'array') && ($tree->root->children[0]->children[0]->children[0]->children[0]->children[0]->name == 'data')){ $rsp = $tree->root->children[0]->children[0]->children[0]->children[0]->children[0]; } if ($tree->root->children[0]->name == 'fault'){ $fault = $tree->root->children[0]; return $fault; } } $nodes = $tree->select_nodes('/methodResponse/params/param[1]/value[1]/array[1]/data[1]/text()'); if (count($nodes)){ $rsp = array_pop($nodes); }else{ list($fault) = $tree->select_nodes('/methodResponse/fault'); return $fault; }
  • 14. Creating API methods • Stateless method-call APIs are easy to extend • Adding a method requires no knowledge of the transport • Adding a method once makes it available to all the interfaces • Self documenting
  • 15. Red Hot Unicode Action • UTF-8 pages • CJKV support • It’s really cool
  • 16.
  • 17. Unicode for all • It’s really easy – Don’t need PHP support – Don’t need MySQL support – Just need the right headers – UTF-8 is 7-bit transparent – (Just don’t mess with high characters) • Don’t use HtmlEntities()! • But bear in mind… • JavaScript has patchy Unicode support • People using your APIs might be stupid
  • 18. Scaling the beast • Why PHP is great • MySQL scaling • Search scaling • Horizontal scaling
  • 19. Why PHP is great • Stateless – We can bounce people around servers – Everything is stored in the database – Even the smarty cache – “Shared nothing” – (so long as we avoid PHP sessions)
  • 20. MySQL Scaling • Our database server started to slow • Load of 200 • Replication!
  • 21. MySQL Replication • But it only gives you more SELECT’s • Else you need to partition vertically • Re-architecting sucks :(
  • 22. Looking at usage • Snapshot of db1.flickr.com – SELECT’s 44,220,588 – INSERT’s 1,349,234 – UPDATE’s 1,755,503 – DELETE’s 318,439 – 13 SELECT’s per I/U/D
  • 23. Replication is really cool • A bunch of slave servers handle all the SELECT’s • A single master just handles I/U/D’s • It can scale horizontally, at least for a while.
  • 24. Searching • A simple text search • We were using RLIKE • Then switched to LIKE • Then disabled it all together
  • 25. FULLTEXT Indexes • MySQL saves the day! • But they’re only supported my MyISAM tables • We use InnoDb, because it’s a lot faster • We’re doomed
  • 26. But wait! • Partial replication saves the day • Replicate the portion of the database we want to search. • But change the table types on the slave to MyISAM • It can keep up because it’s only handling I/U/D’s on a couple of tables • And we can reduce the I/U/D’s with a little bit of vertical partitioning
  • 27. JOIN’s are slow • Normalised data is for sissies • Keep multiple copies of data around • Makes searching faster • Have to ensure consistency in the application logic
  • 28. Our current setup DB1 I/U/D’s Master SELECT’s DB2 Main Slave DB3 Main Search Slave Farm slave Search SELECT’s Search Slave Farm
  • 29. Horizontal scaling • At the core of our design • Just add hardware! • Inexpensive • Not exponential • Avoid redesigns
  • 30. Talking to the Node Service • Everyone speaks XML (badly) • Just TCP/IP - fsockopen() • We’re issuing commands, not requesting data, so we don’t bother to parse the response – Just substring search for state=“ok” • Don’t rely on it!
  • 31. RSS / Atom / RDF • Different formats • All quite bad • We’re generating a lot of different feeds • Abstract the difference away using templates • No good way to do private feeds. Why is nobody working on this? (WSSE maybe?)
  • 32. Receiving email • Want users to be able to email photos to Flickr • Just get postfix to pipe each mail to a PHP script • Parse the mail and find any photos • Cellular phone companies hate you • Lots of mailers are retarded – Photos as text/plain attachments :/
  • 33. Upload via FTP • PHP isn’t so great at being a daemon • Leaks memory like a sieve • No threads • Java to the rescue • Java just acts as an FTPd and passes all uploaded files to PHP for processing • (This isn’t actually public) • Bricolage does this I think. Maybe Zope?
  • 34. Blogs • Why does everyone loves blogs so much? • Only a few APIs really – Blogger – Metaweblog – Blogger2 – Movable Type – Atom – Live Journal
  • 35. It’s all broken • Lots of blog software has broken interfaces • It’s a support nightmare • Manila is tricky • But it all works, more or less • Abstracted in the application logic • We just call blogs_post_message();
  • 36. Back to those APIs • We opened up the Flickr APIs a few weeks ago • Programmers mainly build tools for other programmers • We have Perl, python, PHP, ActionScript, XMLHTTP and .NET interface libraries • But also a few actual applications
  • 39. So what next? • Much more scaling • PHP 5? • MySQL 5? • Taking over the world
  • 40. Flickr and PHP Cal Henderson