SlideShare a Scribd company logo
Web frameworks don't matter
   Web frameworks don't matter




    Web frameworks don’t
           matter.
Some tips, tricks and patterns for designing, scaling and
       maintaining large scale web applications.

                                 Tomas (t0m) Doran

                                 Nordic perl Workshop 2010
                                 São Paulo.pm perl workshop 2010
Introduction
• t0m - Catalyst core team. Moose
  committer. 99 CPAN dists. Silly hair. Idiot ;)
• This is a rant talk about (web) application
  design.
• You get to listen to 3 hours of this today.
  (Sorry about that)
• Please stop me, ask questions, disagree etc.
  (It’ll be more fun, for all of us)
Application design

• Is hard!
• You won’t get it all right first time.
• The web parts are not the main parts
• Yes, even in a web application
Success
• You need to be flexible, requirements will
  change.
• You need to be flexible, your planned
  solutions won’t work
• You need to be flexible, the performance
  inflection points won’t be where you
  predict
Getting the data model right

   • Hint - You won’t..
   • Consistency is the key
   • KISS
   • No broken windows
Getting the data model right

   • You need a consistent and standalone
     model of your application
   • Routing URIs to actions isn’t a hard
     problem
   • Keeping the data from becoming a pile of
     shit is a hard problem
Loosely
              coupled

• You will throw parts of your codebase away
• Components can be tested / replaced
  independently
• Dependency injection
Dependency Injection
Dependency Injection
• Any of the components can be faked /
  mocked / replaced
• Testing becomes much easier (having a test
  MogileFS is a pain in the ass, really!)
• Write factories to build instances so
  dependency injection doesn’t cost.
• Bread::Board?
Efficiency

• Web stuff should be fast!
• Doing extra work on your web servers is
  bad news
• Lots of web processes probably not what
  you want
The PHP fallacy
 Even if extra context switching has zero overhead
       you serve people sooner if you queue.

    A     B       A   B     A     B       A   B

              A                       B


A finishes significantly before B in the lower diagram

        B finishes at the same time in both
Caching strategies

• Page fragments
• Objects and data structures
• Varnish/ESI, mod_cache/SSI
• memcached
• Materialized views (triggers!)
Simple web
 architecture
                                      Load balancer



                                Web server Web server
                                 Web server Web server
                                   Web server Web server
This is how you start and how
most people think about a web
          architecture
                                     Data store
Add a reverse
   proxy                                 Load balancer




                                        Reverse proxy



 Your users are not on a Gb/s      Web server Web server
             pipe.                  Web server Web server
                                      Web server Web server


  Don’t keep your expensive
application processes in IO wait
          sending bytes
                                        Data store
Cache
    expensive                          Load balancer

     lookups
                                      Reverse proxy



Memcache shown here, but this    Web server Web server      Memcache
                                  Web server Web server
   isn’t the only strategy          Web server Web server   Memcache


Materialized views in the data
store layer - denormalisation
      without the pain.
                                      Data store
Using a page
 assembly layer                             PAL




                                        Reverse proxy



                                    Web server Web server      Memcache

   Allows different chunks of        Web server Web server
                                       Web server Web server   Memcache
content to have different caching
           strategies.

Cache even authenticated users           Data store
          (mostly)
Complex
    web
architecture
                                                 PAL




                                             Reverse proxy



                                         Web server Web server      Memcache
Anything that is going to   Message
                                          Web server Web server
                                            Web server Web server   Memcache
   block is run as an        Queue


   asynchronous job
                            Job Server

                                              Data store
Cache stampede!

• Cache flushes can become terminal to your
  application.
• You need to ensure you can avoid this (or
  at least know it’s there)
• Implement switches to ‘cool down’ your
  app
Development,
deployment and testing
• You must use version control
• You must have version numbers
• You must have package management
• You must have a stage environment
Development,
deployment and testing

• You need tests!
• Even if you’re not doing TDD!
• The most likely bug to have is one you
  already fixed once.
Development,
deployment and testing

• Everyone in your team needs to be able to
  do everything
• No superstars, being run over by a bus
  more likely than you think
Development,
deployment and testing

• Test plans
• A-B testing
• Customer driven testing and deployment
Development,
deployment and testing

• You need a rollback plan
• API versioning
• Data migrations - be careful!!
The Zen swap

• Migrating continually updated data around
  with no downtime
• E.g. moving Zen machines between hosts,
  moving database info around.
• For database, relies on triggers
The Zen swap

• Modify time column on ‘from’ table.
• Copy (and munge) all the data, row by row,
  noting when you start
• Copy (and munge) all the data changed
  since you started
• Repeat until the set of dirty data is very
  small
The Zen swap
Old New   Old New   Old New   Old New
The Zen swap
• Stop the universe
• Do one final pass of the data
• Add triggers for reads/writes in the old
  column to use the new column
• Start the universe
• Needs transactional DDL to be seamless
• Even without, use to minimise downtime
Accidental complexity
• Premature generalisation is the root of all
  evil.
• Lack of polymorphism
• Insufficient use of delegation
• Commonality develops independently.You
  MUST refactor
Load and scalability
         testing
• Simple ab can tell you a lot
• NYTProf
• You need to test your system with your
  hardware and your data
• A little tuning can go a long way.
Health monitoring
• Log useful stuff from your app!
• Syslog
• Nagios
• Healthcheck pages
• Munin
• Splunk
Performance
          monitoring

• Per hit stats (db queries, memcache hits,
  times taken)
• Query comments
• Graphs are awesome (RRD is kinda hateful)
Conclusion

• Components rule!
• Expect change.
• Enforce consistency.
Thanks!

• Slides will be on slideshare later
• I can (and probably will) rant at length
  about any of this if you buy me a beer ;)
• Questions?

More Related Content

KEY
Deploying Plack Web Applications: OSCON 2011
PDF
Building real time applications with Symfony2
PDF
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
PDF
ZendCon 2015 - DevOps for Small Teams
PDF
Tips for going fast in a slow world: Michael May at OSCON 2015
PPTX
how to mesure web performance metrics
PPTX
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
PDF
Varnish Cache Plus. Random notes for wise web developers
Deploying Plack Web Applications: OSCON 2011
Building real time applications with Symfony2
ApacheConNA 2015: Apache httpd 2.4 Reverse Proxy
ZendCon 2015 - DevOps for Small Teams
Tips for going fast in a slow world: Michael May at OSCON 2015
how to mesure web performance metrics
Масштабируя TLS / Артём Гавриченков (Qrator Labs)
Varnish Cache Plus. Random notes for wise web developers

What's hot (20)

PDF
Can you contain the future - Docker, Container Technologies, The Future, and You
PDF
The State of WebSockets in Django
PDF
Deploying Symfony | symfony.cat
PDF
DevOps tools for everyone - Vagrant, Puppet and Webmin
PDF
Building a better web
PDF
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
PPTX
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
PDF
Web Leaps Forward
PDF
How do I Write Testable Javascript so I can Test my CF API on Server and Client
PDF
Hack & Fix, Hands on ColdFusion Security Training
PDF
Single page apps with drupal 7
PPTX
My Database Skills Killed the Server
PPTX
Advanced Caching Concepts @ Velocity NY 2015
PDF
Cfml features modern_coding
PDF
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
PDF
Converting Your Dev Environment to a Docker Stack - Cascadia
KEY
Scaling Django
PDF
Converting Your Dev Environment to a Docker Stack - php[world]
PDF
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
PPTX
Ruby in the Browser - RubyConf 2011
Can you contain the future - Docker, Container Technologies, The Future, and You
The State of WebSockets in Django
Deploying Symfony | symfony.cat
DevOps tools for everyone - Vagrant, Puppet and Webmin
Building a better web
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
Mitigating Security Threats with Fastly - Joe Williams at Fastly Altitude 2015
Web Leaps Forward
How do I Write Testable Javascript so I can Test my CF API on Server and Client
Hack & Fix, Hands on ColdFusion Security Training
Single page apps with drupal 7
My Database Skills Killed the Server
Advanced Caching Concepts @ Velocity NY 2015
Cfml features modern_coding
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
Converting Your Dev Environment to a Docker Stack - Cascadia
Scaling Django
Converting Your Dev Environment to a Docker Stack - php[world]
Apache HTTPD 2.4 Reverse Proxy: The Hidden Gem
Ruby in the Browser - RubyConf 2011
Ad

Similar to Web frameworks don't matter (20)

PDF
Evolving Archetecture
PPT
Large-scale projects development (scaling LAMP)
PDF
Scale Fail: How I Learned to Love the Downtime
PPTX
Women Who Code, Ground Floor
PDF
High Scalability Toronto: Meetup #2
PDF
Top ten-list
PDF
The Web Scale
PDF
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
PDF
Fixing twitter
PDF
Fixing_Twitter
PDF
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
PPTX
Scalable Web Architecture and Distributed Systems
PPS
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYC
PPT
Top 10 Scalability Mistakes
PDF
Your backend architecture is what matters slideshare
PPT
Apache Con 2008 Top 10 Mistakes
PPS
Scalable Web Arch
PPS
Scalable Web Architectures - Common Patterns & Approaches
PPT
Web Speed And Scalability
KEY
Fixing Twitter Velocity2009
Evolving Archetecture
Large-scale projects development (scaling LAMP)
Scale Fail: How I Learned to Love the Downtime
Women Who Code, Ground Floor
High Scalability Toronto: Meetup #2
Top ten-list
The Web Scale
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Fixing twitter
Fixing_Twitter
Fixing Twitter Improving The Performance And Scalability Of The Worlds Most ...
Scalable Web Architecture and Distributed Systems
Scalable Web Architectures: Common Patterns and Approaches - Web 2.0 Expo NYC
Top 10 Scalability Mistakes
Your backend architecture is what matters slideshare
Apache Con 2008 Top 10 Mistakes
Scalable Web Arch
Scalable Web Architectures - Common Patterns & Approaches
Web Speed And Scalability
Fixing Twitter Velocity2009
Ad

More from Tomas Doran (20)

PPTX
Long haul infrastructure: Failures and successes
PDF
Empowering developers to deploy their own data stores
PDF
Dockersh and a brief intro to the docker internals
PDF
Sensu and Sensibility - Puppetconf 2014
PDF
Steamlining your puppet development workflow
PDF
Building a smarter application stack - service discovery and wiring for Docker
PDF
Chasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
PPT
Deploying puppet code at light speed
PDF
Thinking through puppet code layout
PDF
Docker puppetcamp london 2013
PDF
"The worst code I ever wrote"
PDF
Test driven infrastructure development (2 - puppetconf 2013 edition)
PDF
Test driven infrastructure development
PPT
London devops - orc
KEY
London devops logging
KEY
Message:Passing - lpw 2012
KEY
Webapp security testing
KEY
Webapp security testing
KEY
Dates aghhhh!!?!?!?!
KEY
Messaging, interoperability and log aggregation - a new framework
Long haul infrastructure: Failures and successes
Empowering developers to deploy their own data stores
Dockersh and a brief intro to the docker internals
Sensu and Sensibility - Puppetconf 2014
Steamlining your puppet development workflow
Building a smarter application stack - service discovery and wiring for Docker
Chasing AMI - Building Amazon machine images with Puppet, Packer and Jenkins
Deploying puppet code at light speed
Thinking through puppet code layout
Docker puppetcamp london 2013
"The worst code I ever wrote"
Test driven infrastructure development (2 - puppetconf 2013 edition)
Test driven infrastructure development
London devops - orc
London devops logging
Message:Passing - lpw 2012
Webapp security testing
Webapp security testing
Dates aghhhh!!?!?!?!
Messaging, interoperability and log aggregation - a new framework

Web frameworks don't matter

  • 1. Web frameworks don't matter Web frameworks don't matter Web frameworks don’t matter. Some tips, tricks and patterns for designing, scaling and maintaining large scale web applications. Tomas (t0m) Doran Nordic perl Workshop 2010 São Paulo.pm perl workshop 2010
  • 2. Introduction • t0m - Catalyst core team. Moose committer. 99 CPAN dists. Silly hair. Idiot ;) • This is a rant talk about (web) application design. • You get to listen to 3 hours of this today. (Sorry about that) • Please stop me, ask questions, disagree etc. (It’ll be more fun, for all of us)
  • 3. Application design • Is hard! • You won’t get it all right first time. • The web parts are not the main parts • Yes, even in a web application
  • 4. Success • You need to be flexible, requirements will change. • You need to be flexible, your planned solutions won’t work • You need to be flexible, the performance inflection points won’t be where you predict
  • 5. Getting the data model right • Hint - You won’t.. • Consistency is the key • KISS • No broken windows
  • 6. Getting the data model right • You need a consistent and standalone model of your application • Routing URIs to actions isn’t a hard problem • Keeping the data from becoming a pile of shit is a hard problem
  • 7. Loosely coupled • You will throw parts of your codebase away • Components can be tested / replaced independently • Dependency injection
  • 9. Dependency Injection • Any of the components can be faked / mocked / replaced • Testing becomes much easier (having a test MogileFS is a pain in the ass, really!) • Write factories to build instances so dependency injection doesn’t cost. • Bread::Board?
  • 10. Efficiency • Web stuff should be fast! • Doing extra work on your web servers is bad news • Lots of web processes probably not what you want
  • 11. The PHP fallacy Even if extra context switching has zero overhead you serve people sooner if you queue. A B A B A B A B A B A finishes significantly before B in the lower diagram B finishes at the same time in both
  • 12. Caching strategies • Page fragments • Objects and data structures • Varnish/ESI, mod_cache/SSI • memcached • Materialized views (triggers!)
  • 13. Simple web architecture Load balancer Web server Web server Web server Web server Web server Web server This is how you start and how most people think about a web architecture Data store
  • 14. Add a reverse proxy Load balancer Reverse proxy Your users are not on a Gb/s Web server Web server pipe. Web server Web server Web server Web server Don’t keep your expensive application processes in IO wait sending bytes Data store
  • 15. Cache expensive Load balancer lookups Reverse proxy Memcache shown here, but this Web server Web server Memcache Web server Web server isn’t the only strategy Web server Web server Memcache Materialized views in the data store layer - denormalisation without the pain. Data store
  • 16. Using a page assembly layer PAL Reverse proxy Web server Web server Memcache Allows different chunks of Web server Web server Web server Web server Memcache content to have different caching strategies. Cache even authenticated users Data store (mostly)
  • 17. Complex web architecture PAL Reverse proxy Web server Web server Memcache Anything that is going to Message Web server Web server Web server Web server Memcache block is run as an Queue asynchronous job Job Server Data store
  • 18. Cache stampede! • Cache flushes can become terminal to your application. • You need to ensure you can avoid this (or at least know it’s there) • Implement switches to ‘cool down’ your app
  • 19. Development, deployment and testing • You must use version control • You must have version numbers • You must have package management • You must have a stage environment
  • 20. Development, deployment and testing • You need tests! • Even if you’re not doing TDD! • The most likely bug to have is one you already fixed once.
  • 21. Development, deployment and testing • Everyone in your team needs to be able to do everything • No superstars, being run over by a bus more likely than you think
  • 22. Development, deployment and testing • Test plans • A-B testing • Customer driven testing and deployment
  • 23. Development, deployment and testing • You need a rollback plan • API versioning • Data migrations - be careful!!
  • 24. The Zen swap • Migrating continually updated data around with no downtime • E.g. moving Zen machines between hosts, moving database info around. • For database, relies on triggers
  • 25. The Zen swap • Modify time column on ‘from’ table. • Copy (and munge) all the data, row by row, noting when you start • Copy (and munge) all the data changed since you started • Repeat until the set of dirty data is very small
  • 26. The Zen swap Old New Old New Old New Old New
  • 27. The Zen swap • Stop the universe • Do one final pass of the data • Add triggers for reads/writes in the old column to use the new column • Start the universe • Needs transactional DDL to be seamless • Even without, use to minimise downtime
  • 28. Accidental complexity • Premature generalisation is the root of all evil. • Lack of polymorphism • Insufficient use of delegation • Commonality develops independently.You MUST refactor
  • 29. Load and scalability testing • Simple ab can tell you a lot • NYTProf • You need to test your system with your hardware and your data • A little tuning can go a long way.
  • 30. Health monitoring • Log useful stuff from your app! • Syslog • Nagios • Healthcheck pages • Munin • Splunk
  • 31. Performance monitoring • Per hit stats (db queries, memcache hits, times taken) • Query comments • Graphs are awesome (RRD is kinda hateful)
  • 32. Conclusion • Components rule! • Expect change. • Enforce consistency.
  • 33. Thanks! • Slides will be on slideshare later • I can (and probably will) rant at length about any of this if you buy me a beer ;) • Questions?