Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Symfony High Availability in the Cloud

Frank Neff
September 16, 2015

Symfony High Availability in the Cloud

Slides of my talk at the Symfony Usergroup Zurich

Frank Neff

September 16, 2015
Tweet

More Decks by Frank Neff

Other Decks in Programming

Transcript

  1. FSEEKING YEAH! • Single server instance • Slow I/O •

    Shared Memory • Virtualised CPU • No idea where our service is hosted
  2. THIS IS HA • Redundant Setup • Load is balanced

    • No resource conflicts • Every Service / Component can break
  3. MICRO INSTANCES Architecture • Database / Webserver / Cache 


    on same host • Lowers network traffic • Bigger impact in case of failure • Fewer machines needed / Cheap • Risk of resource conflicts • Harder to debug / identify bottlenecks
  4. ONE SERVICE PER HOST Architecture • Database / Webserver /

    Cache 
 on own hosts • High internal network traffic • More instances needed (expensive) • Guaranteed resources • Easy to identify bottlenecks • Better performance in case of failure
  5. MULTI-SITE DISTRIBUTION Architecture • Service groups are distributed over
 dedicated

    physical hardware • Multi-site application hosting 
 in different data centres • Synchonization traffic between 
 data centers (Internet / fibre channel) • Disaster safe • Complex and very expensive • “SysOp Porn”
  6. GENERAL CODING • Always think about multiple, simultaneous instances while

    coding • Every application-state must be shared somehow with all other nodes • If one node fails, it must not block others • Avoid long running processes
  7. COMMON PITFALLS • Session management • (Cron-) Jobs • SSL

    Termination • Replication lag • Asset delivery
  8. SESSION MANAGEMENT • PHP cannot share sessions across servers (IMHO)

    • Sessions for shops, admin-backends, etc. must be handled in distributed systems • Persist sessions in Memcache / Redis • Use sticky sessions
  9. (CRON-) JOBS • When jobs run in a distributed environment,

    they can disrupt each other • Data inconsistencies / Things get broken • Run jobs on dedicated job-server(s) • Use distributed locking / mutex
  10. SSL TERMINATION • Regarding SSL, it should not make a

    difference on which server you are • Terminate SSL on your load balancer or caching reverse proxy • Varnish and HAProxy both support SSL termination
  11. REPLICATION LAG • Can happen when you are using master/slave

    replication on your DB • One big problem of distributed apps, 
 even for Facebook (e.g.) • There is no perfect solution for dealing with it, but awareness • See CAP-Theorem
  12. ASSET DELIVERY • Delivering CSS, JS and images can become

    a performance bottleneck • Avoid booting a Symfony stack for asset delivery • Cache assets (e.g. with Varnish) or use a CDN for asset delivery • Rename assets to invalidate caches
  13. CACHE / LB • Varnish 4 • Used for asset

    delivery and HTTP caching • Acts as load balancer for web servers • Only instance which is publicly accessible
  14. JOB SERVER • Outsource heavy jobs to a separate server

    • Cron / Supervisord / Gearman • Runs PHP / Symfony but without a webserver • Should have own DB instance
  15. JOB SERVER HA • Don’t run multiple job servers •

    Run second / third as active standby • Distribute jobs over different active servers • Utilize distributed locking (e.g. Zookeeper)
  16. MONITORING • Use a centralized monitoring solution • Keep watching

    your app instances (e.g. while deploying) • Identify performance issues / bottlenecks using visualization • Datadog, Nagios, Icinga, NewRelic, etc…
  17. THANKS Symfony Routing Under the Hood (Liip / 21.10.) Show

    me Your Bundles #2 (iBROWS /18.11) Upcoming Meetups @frank_neff / frankneff.ch