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

Growing X20 without spending an extra penny on ...

Growing X20 without spending an extra penny on hosting

A year ago we started a big change in FTBpro. We completely changed the visual design, moved to a single page architecture and started exploring new ways to minimise load on our servers - both when serving our actual website, and mobile API responses.We'll focus on how scaling considerations are now an integral part of our architecture, which enabled us to serve 20x more traffic than we did 1 year ago, with the same setup and with no additional costs.

Dor Kalev

May 20, 2014
Tweet

More Decks by Dor Kalev

Other Decks in Technology

Transcript

  1. Single Page Application Phantom.js renders pages on the server-side for

    SEO, crawlers and mobile web performance Load Balancer Memcached Redis Web 1 Web 2 Web 3 MySQL MongoDB ElasticSearch Amazon Web Services NginX + Ruby on Rails PhantomJS Web 4
  2. Each Render Server can return 1 client request at a

    time 1:1 Client Server
 Render
  3. A cache server can handle over x10 more traffic 10:1:1

    Cache Server Render Client Client Client Client Client Client Client Client Client Client Client Client
  4. Cache server still consumes CPU and with more traffic, more

    servers are needed 20:2:1 Cache Server Render Cache Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client
  5. Accelerator like NGINX+MemCached or Varnish can be x100 more efficient

    than plain App Server Cache 100:1:1 Server Render Accelerator Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client https://www.igvita.com/2008/02/11/nginx-and-memcached-a-400-boost/ https://www.varnish-cache.org
  6. 200:2:1 Server Render Accelerator Accelerator Client Client Client Client Client

    Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Accelerator also runs on limited hardware and needs more CPU in order to scale
  7. Enter CDN ∞:1 Client Client Client Client Client Client Client

    Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client CDN Server Render
  8. Client Client My Tiny Server PoP CDN SERVER CDN SERVER

    CDN SERVER PoP CDN SERVER CDN SERVER CDN SERVER PoP CDN SERVER CDN SERVER CDN SERVER Client Client Client Client Client Client Client What’s a CDN?
  9. What’s a CDN? • Content Delivery Network • A set

    of autonomic distributed cache servers • Serve cache from a location geographically close to the client • e.g: Akamai, Cloudflare, Fastly, Highwinds, Edgecast, Cloudfront
  10. Enter Trouble ∞:1 Client Client Client Client Client Client Client

    Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client Client CDN Server Render
  11. Purge by TTL - isn’t realtime & causes redundant server

    hits CPU LOAD 0 7.5 15 22.5 30 TIME 1 2 3 4 5 (TTL) 6 7 8 9 (TTL) 10 11 12
  12. multiply by all articles CPU LOAD 0 7.5 15 22.5

    30 TIME 1 2 3 4 5 (TTL) 6 7 8 9 (TTL) 10 11 12
  13. TTL = Constant waste of CPU CPU LOAD 0 7.5

    15 22.5 30 TIME 1 2 3 4 5 6 7 8 9 10 11 12
  14. cache forever +
 purge on demand 0 7.5 15 22.5

    30 1 (release) 2 3 4 5 6 7 8 9 (purge) 10 11 12
  15. Caveats • Purging everything can lead to downtime, e.g. when

    deploying • User Specific content can’t be cached with the entire page • Downtime on massive Push Notifications
  16. Massive Push Notification + cold CDN Cache = traffic goes

    to app servers CPU LOAD 0 250 500 750 1000 TIME 1 (PN) 2 3 4 5 6 7 8 9 10 11 12
  17. Client Client My Tiny Server PoP CDN SERVER CDN SERVER

    CDN SERVER PoP CDN SERVER CDN SERVER CDN SERVER PoP CDN SERVER CDN SERVER CDN SERVER Client Client Client Client Client Client Client Render (or cache & serve) X number of calls
 in parallel = self-DDoS
  18. Client Client CACHE PoP CDN SERVER CDN SERVER CDN SERVER

    PoP CDN SERVER CDN SERVER CDN SERVER PoP CDN SERVER CDN SERVER CDN SERVER Client Client Client Client Client Client Client Solution: Another local cache layer & Preload CDN
 (few CDNs have this feature, e.g. EdgeCast) My Tiny Server
  19. CPU vs TRAFFIC • 13:53 preloaded post to CDN •

    13:55 PN sent • 13:57+ traffic stops @ CDN servers, no CPU throughput • 14:00 …
  20. Summary • CDN allows massive scale • Smart CDN usage

    allows even more scale • Scale + fresh content + low hosting prices is a do-able mission ! Questions?
  21. Read More… • Growing X20 without spending an extra penny

    on hosting (The original blog post)
 http://tech.ftbpro.com/post/78969626647/growing-x20-without-spending-an-extra-penny-on-hosting • Single Page Applications Done Right
 http://tech.ftbpro.com/post/84720180206/single-page-applications-done-right • Count von Count - Real time counting DB
 http://tech.ftbpro.com/post/73212710968/count-von-count-a-real-time-counting-database • The Dark Side of Single Page Applications
 http://tech.ftbpro.com/post/66182501420/the-dark-side-of-single-page-applications-rails OSS: http://github.com/ftbpro
 BLOG: http://tech.ftbpro.com