Realtime web2012

Timothy Fitz
Timothy FitzIndependent Contractor at Timothy Fitz
Building Real-Time Web
http://tinyurl.com/realtime2012

     http://   Timothy Fitz .com
                 CTO Canvas
What is “Realtime web”
What does “Realtime” look like?
What does “Realtime” look like?
What does “Realtime” look like?
“Push, not pull.”

REALTIME WEB
Talking to the browser
High concurrency
Scaling up

3 HARD PROBLEMS
Talking to the browser
•   Short Polling
•   Long Polling
•   WebSocket
•   Flash Socket
Short Polling
Long Polling
Flash Socket
WebSocket
High Concurrency
• Blocking I/O
  – Thread per process
  – Tops out at 200 to 1k connections
• Non-blocking I/O
  – One process, one thread
  – 10k to 100k connections
Django
Django
 Apache
There is no apache for realtime
Non-blocking I/O Servers
• Python
  – Twisted
  – Tornado
  – gevent
• Not python
  – Node.js
  – Erlang something
Twisted
• Pro
  – Can talk every protocol ever
  – Oldest and most widely used in production
• Con
  – Overkill for web-only tasks
  – Not simple
Tornado
• Pro
  – Simple
  – Does HTTP stuff simply
• Con
  – Might not interface with what you need
• Confusing
  – You can run Tornado (HTTP layer) on top of
    Twisted (networking layer)
gevent
• Pro
  – Coroutines are a better model than callbacks
  – As such, very easy to write complicated logic
• Con
  – Least well documented
  – Least consensus on best practices
  – New, uncertain about production readiness
Node.js
• Pro
  – Best documentation by far
  – Socket.IO abstracts away browser communication
• Con
  – Can’t share logic between Django app
  – New, but has fairly large install base
Erlang
• Pro
  – Hands down best for complex realtime tasks
  – Forces you to think about concurrency/scale
  – Abstracts away the network
  – Old and reliable
• Con
  – Forces you to think about concurrency/scale
  – Can’t share logic between Django app
  – High spin-up cost (functional, concurrency driven)
Just one
Frontend nodes x Backend nodes
More architecture decisions!

SCALING UP!
Just one
•   Everything in memory
•   Django nodes talk directly to box
•   Spare for availability
•   Failover = realtime data loss
    – Make realtime 100% redundant
Probably good enough!
– WARNING: NAPKIN MATH
– 10k daily visits * 10.0min avg visit
  = 70 average concurrent users
– One box can easily be built out to handle 3-5k
  = Roughly 450k-700k daily visits
Frontend nodes x Backend nodes
• Frontend handle users / connections
• Backend handles channels
More architecture decisions!
• In memory backend
  – Redis Pub/Sub
  – ZeroMQ
  – Roll your own
• Persisted to Disk:
  – ActiveMQ
  – RabbitMQ
  – Amazon SQS
Redis Pub/Sub
•   Simplest to setup
•   Simplest model
•   SUBSCRIBE channel_name
•   PUBLISH channel_name “Hello World!”
ZeroMQ
•   Publish/Subscribe semantics
•   Request/Response
•   Push/Pull (round robin)
•   Extremely fast
Roll your own
• Same language as your frontend
  – (Twisted/Node/Whatever)
• Only do this if you have per-channel business
  logic
  – You probably don’t.
• Erlang maps really really well to this domain.
Full Stack Services
• REST APIs to push to the browser
• http://pusher.com
• http://beaconpush.com
Canvas

Amazon ELB   Nginx + Twisted   Redis
Final Recommendations
•   Need python? Twisted
•   Don’t? Node.js/SocketIO
•   Need scale/reliability? Redis backend.
•   Complex? Going big? Erlang all the way.
Questions?
Further Reading
• IMVU IMQ talk http://www.slideshare.net/JonWatte/message-queuing-
  on-a-large-scale-imvus-stateful-realtime-message-queue
• Twilio talk on gevent + zeromq (given by Jeff Lindsay, highly recomended):
  http://www.twilio.com/conference/video/distributed-systems-with-
  gevent-and-zeromq
• Last.fm scaling Eralng/Mochiweb to 1 million concurrent connections on
  one machine: http://www.metabrew.com/article/a-million-user-comet-
  application-with-mochiweb-part-1
• The original Comet blog post: http://infrequently.org/2006/03/comet-low-
  latency-data-for-the-browser/
• Django + Socket.IO + gevent:
  http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio-
  and-gevent/
1 of 35

Recommended

EhTrace -- RoP Hooks by
EhTrace -- RoP HooksEhTrace -- RoP Hooks
EhTrace -- RoP HooksShane Macaulay
253 views25 slides
Resumable File Upload API using GridFS and TUS by
Resumable File Upload API using GridFS and TUSResumable File Upload API using GridFS and TUS
Resumable File Upload API using GridFS and TUSkhangtoh
3.5K views29 slides
Tus.io presentation for iOS devscout meetup by
Tus.io presentation for  iOS devscout meetupTus.io presentation for  iOS devscout meetup
Tus.io presentation for iOS devscout meetupkhangtoh
627 views27 slides
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen... by
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...PHP Conference Argentina
1.9K views19 slides
tus.io – Resumable file uploads for web and mobile apps by Felix Geisendörfer by
tus.io – Resumable file uploads for web and mobile apps by Felix Geisendörfertus.io – Resumable file uploads for web and mobile apps by Felix Geisendörfer
tus.io – Resumable file uploads for web and mobile apps by Felix GeisendörferCodemotion
4.9K views52 slides
Stabilizing SE Build - Selenium conf 2013 by
Stabilizing SE Build - Selenium conf 2013 Stabilizing SE Build - Selenium conf 2013
Stabilizing SE Build - Selenium conf 2013 dimakovalenko
3.9K views28 slides

More Related Content

What's hot

Rabbits, indians and... Symfony meets queueing brokers by
Rabbits, indians and...  Symfony meets queueing brokersRabbits, indians and...  Symfony meets queueing brokers
Rabbits, indians and... Symfony meets queueing brokersGaetano Giunta
2.7K views33 slides
Ruby Concurrency Realities by
Ruby Concurrency RealitiesRuby Concurrency Realities
Ruby Concurrency RealitiesMike Subelsky
1.5K views55 slides
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker) by
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)Grant Norwood
3.8K views42 slides
Zero mq logs by
Zero mq logsZero mq logs
Zero mq logsTomas Doran
4.5K views54 slides
Perconalive feb-2011-share by
Perconalive feb-2011-sharePerconalive feb-2011-share
Perconalive feb-2011-sharemdcallag
1.6K views53 slides
Hybrid concurrency patterns by
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patternsKyle Drake
15.2K views45 slides

What's hot(20)

Rabbits, indians and... Symfony meets queueing brokers by Gaetano Giunta
Rabbits, indians and...  Symfony meets queueing brokersRabbits, indians and...  Symfony meets queueing brokers
Rabbits, indians and... Symfony meets queueing brokers
Gaetano Giunta2.7K views
Ruby Concurrency Realities by Mike Subelsky
Ruby Concurrency RealitiesRuby Concurrency Realities
Ruby Concurrency Realities
Mike Subelsky1.5K views
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker) by Grant Norwood
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Grant Norwood3.8K views
Perconalive feb-2011-share by mdcallag
Perconalive feb-2011-sharePerconalive feb-2011-share
Perconalive feb-2011-share
mdcallag1.6K views
Hybrid concurrency patterns by Kyle Drake
Hybrid concurrency patternsHybrid concurrency patterns
Hybrid concurrency patterns
Kyle Drake15.2K views
STAQ Development Manual (Redacted) by Mike Subelsky
STAQ Development Manual (Redacted)STAQ Development Manual (Redacted)
STAQ Development Manual (Redacted)
Mike Subelsky5.6K views
Get Off My Thread! - keep your UI super-responsive by DroidConTLV
Get Off My Thread! - keep your UI super-responsiveGet Off My Thread! - keep your UI super-responsive
Get Off My Thread! - keep your UI super-responsive
DroidConTLV2.4K views
Making Symfony Services async with RabbitMq (and more Symfony) by Gaetano Giunta
Making Symfony Services async with RabbitMq (and more Symfony)Making Symfony Services async with RabbitMq (and more Symfony)
Making Symfony Services async with RabbitMq (and more Symfony)
Gaetano Giunta1.1K views
Big Data! Great! Now What? #SymfonyCon 2014 by Ricard Clau
Big Data! Great! Now What? #SymfonyCon 2014Big Data! Great! Now What? #SymfonyCon 2014
Big Data! Great! Now What? #SymfonyCon 2014
Ricard Clau23.4K views
Ratpack for Real by TomAkehurst
Ratpack for RealRatpack for Real
Ratpack for Real
TomAkehurst483 views
Riak at Posterous by capotej
Riak at PosterousRiak at Posterous
Riak at Posterous
capotej13.8K views
Dark Fairytales from a Phisherman by Michele Orru
Dark Fairytales from a PhishermanDark Fairytales from a Phisherman
Dark Fairytales from a Phisherman
Michele Orru4.9K views
What's new in Symfony3 by Yuki MAEJIMA
What's new in Symfony3What's new in Symfony3
What's new in Symfony3
Yuki MAEJIMA4.4K views
Designing a Docker Stack for Symfony apps: lessons learned by Gaetano Giunta
Designing a Docker Stack  for Symfony apps: lessons learnedDesigning a Docker Stack  for Symfony apps: lessons learned
Designing a Docker Stack for Symfony apps: lessons learned
Gaetano Giunta573 views
Woo: Writing a fast web server by fukamachi
Woo: Writing a fast web serverWoo: Writing a fast web server
Woo: Writing a fast web server
fukamachi3K views

Similar to Realtime web2012

Html5 web sockets - Brad Drysdale - London Web 2011-10-20 by
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Nathan O'Hanlon
1.8K views83 slides
Messaging, interoperability and log aggregation - a new framework by
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkTomas Doran
3K views67 slides
Scaling with Symfony - PHP UK by
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UKRicard Clau
13K views49 slides
Life Beyond Rails: Creating Cross Platform Ruby Apps by
Life Beyond Rails: Creating Cross Platform Ruby AppsLife Beyond Rails: Creating Cross Platform Ruby Apps
Life Beyond Rails: Creating Cross Platform Ruby AppsTristan Gomez
322 views67 slides
The State of WebSockets in Django by
The State of WebSockets in DjangoThe State of WebSockets in Django
The State of WebSockets in DjangoRami Sayar
13K views25 slides

Similar to Realtime web2012(20)

Html5 web sockets - Brad Drysdale - London Web 2011-10-20 by Nathan O'Hanlon
Html5 web sockets - Brad Drysdale - London Web 2011-10-20Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Nathan O'Hanlon1.8K views
Messaging, interoperability and log aggregation - a new framework by Tomas Doran
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
Tomas Doran3K views
Scaling with Symfony - PHP UK by Ricard Clau
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
Ricard Clau13K views
Life Beyond Rails: Creating Cross Platform Ruby Apps by Tristan Gomez
Life Beyond Rails: Creating Cross Platform Ruby AppsLife Beyond Rails: Creating Cross Platform Ruby Apps
Life Beyond Rails: Creating Cross Platform Ruby Apps
Tristan Gomez322 views
The State of WebSockets in Django by Rami Sayar
The State of WebSockets in DjangoThe State of WebSockets in Django
The State of WebSockets in Django
Rami Sayar13K views
From a student to an apache committer practice of apache io tdb by jixuan1989
From a student to an apache committer  practice of apache io tdbFrom a student to an apache committer  practice of apache io tdb
From a student to an apache committer practice of apache io tdb
jixuan1989552 views
High performance network programming on the jvm oscon 2012 by Erik Onnen
High performance network programming on the jvm   oscon 2012 High performance network programming on the jvm   oscon 2012
High performance network programming on the jvm oscon 2012
Erik Onnen121.6K views
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony by Kyle Drake
Fast, concurrent ruby web applications with EventMachine and EM::SynchronyFast, concurrent ruby web applications with EventMachine and EM::Synchrony
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake9.7K views
Modern software architectures - PHP UK Conference 2015 by Ricard Clau
Modern software architectures - PHP UK Conference 2015Modern software architectures - PHP UK Conference 2015
Modern software architectures - PHP UK Conference 2015
Ricard Clau3.7K views
Lares from LOW to PWNED by Chris Gates
Lares from LOW to PWNEDLares from LOW to PWNED
Lares from LOW to PWNED
Chris Gates6.4K views
Three years of OFELIA - taking stock by FIBRE Testbed
Three years of OFELIA - taking stockThree years of OFELIA - taking stock
Three years of OFELIA - taking stock
FIBRE Testbed723 views
John adams talk cloudy by John Adams
John adams   talk cloudyJohn adams   talk cloudy
John adams talk cloudy
John Adams3.3K views
Vert.x introduction by GR8Conf
Vert.x introductionVert.x introduction
Vert.x introduction
GR8Conf7K views
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013 by Amazon Web Services
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Cloud Connected Devices on a Global Scale (CPN303) | AWS re:Invent 2013
Amazon Web Services2.5K views
Phoenix for Rubyists by Doug Goldie
Phoenix for RubyistsPhoenix for Rubyists
Phoenix for Rubyists
Doug Goldie109 views

More from Timothy Fitz

Good hypothesis testing is surprising! by
Good hypothesis testing is surprising!Good hypothesis testing is surprising!
Good hypothesis testing is surprising!Timothy Fitz
1K views26 slides
Continuous Deployment: Beyond Continuous Delivery by
Continuous Deployment: Beyond Continuous DeliveryContinuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous DeliveryTimothy Fitz
2.8K views95 slides
Gdc 2010 architecture final slideshare edition by
Gdc 2010 architecture final slideshare editionGdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare editionTimothy Fitz
697 views27 slides
Scaling Up Continuous Deployment by
Scaling Up Continuous DeploymentScaling Up Continuous Deployment
Scaling Up Continuous DeploymentTimothy Fitz
1.5K views20 slides
The Hard Problems of Continuous Deployment by
The Hard Problems of Continuous DeploymentThe Hard Problems of Continuous Deployment
The Hard Problems of Continuous DeploymentTimothy Fitz
3.6K views36 slides
Continuous Deployment by
Continuous DeploymentContinuous Deployment
Continuous DeploymentTimothy Fitz
1.9K views22 slides

More from Timothy Fitz(12)

Good hypothesis testing is surprising! by Timothy Fitz
Good hypothesis testing is surprising!Good hypothesis testing is surprising!
Good hypothesis testing is surprising!
Timothy Fitz1K views
Continuous Deployment: Beyond Continuous Delivery by Timothy Fitz
Continuous Deployment: Beyond Continuous DeliveryContinuous Deployment: Beyond Continuous Delivery
Continuous Deployment: Beyond Continuous Delivery
Timothy Fitz2.8K views
Gdc 2010 architecture final slideshare edition by Timothy Fitz
Gdc 2010 architecture final slideshare editionGdc 2010 architecture final slideshare edition
Gdc 2010 architecture final slideshare edition
Timothy Fitz697 views
Scaling Up Continuous Deployment by Timothy Fitz
Scaling Up Continuous DeploymentScaling Up Continuous Deployment
Scaling Up Continuous Deployment
Timothy Fitz1.5K views
The Hard Problems of Continuous Deployment by Timothy Fitz
The Hard Problems of Continuous DeploymentThe Hard Problems of Continuous Deployment
The Hard Problems of Continuous Deployment
Timothy Fitz3.6K views
Continuous Deployment by Timothy Fitz
Continuous DeploymentContinuous Deployment
Continuous Deployment
Timothy Fitz1.9K views
Continuous Deployment by Timothy Fitz
Continuous DeploymentContinuous Deployment
Continuous Deployment
Timothy Fitz838 views
Continuous Deployment by Timothy Fitz
Continuous DeploymentContinuous Deployment
Continuous Deployment
Timothy Fitz2.8K views
Just In Time Scalability Agile Methods To Support Massive Growth Presentation by Timothy Fitz
Just In Time Scalability  Agile Methods To Support Massive Growth PresentationJust In Time Scalability  Agile Methods To Support Massive Growth Presentation
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Timothy Fitz1.3K views

Recently uploaded

Evolving the Network Automation Journey from Python to Platforms by
Evolving the Network Automation Journey from Python to PlatformsEvolving the Network Automation Journey from Python to Platforms
Evolving the Network Automation Journey from Python to PlatformsNetwork Automation Forum
13 views21 slides
Tunable Laser (1).pptx by
Tunable Laser (1).pptxTunable Laser (1).pptx
Tunable Laser (1).pptxHajira Mahmood
24 views37 slides
Voice Logger - Telephony Integration Solution at Aegis by
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at AegisNirmal Sharma
39 views1 slide
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
41 views73 slides
The Research Portal of Catalonia: Growing more (information) & more (services) by
The Research Portal of Catalonia: Growing more (information) & more (services)The Research Portal of Catalonia: Growing more (information) & more (services)
The Research Portal of Catalonia: Growing more (information) & more (services)CSUC - Consorci de Serveis Universitaris de Catalunya
80 views25 slides
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensorssugiuralab
19 views15 slides

Recently uploaded(20)

Voice Logger - Telephony Integration Solution at Aegis by Nirmal Sharma
Voice Logger - Telephony Integration Solution at AegisVoice Logger - Telephony Integration Solution at Aegis
Voice Logger - Telephony Integration Solution at Aegis
Nirmal Sharma39 views
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors by sugiuralab
TouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective SensorsTouchLog: Finger Micro Gesture Recognition  Using Photo-Reflective Sensors
TouchLog: Finger Micro Gesture Recognition Using Photo-Reflective Sensors
sugiuralab19 views
Transcript: The Details of Description Techniques tips and tangents on altern... by BookNet Canada
Transcript: The Details of Description Techniques tips and tangents on altern...Transcript: The Details of Description Techniques tips and tangents on altern...
Transcript: The Details of Description Techniques tips and tangents on altern...
BookNet Canada136 views
STPI OctaNE CoE Brochure.pdf by madhurjyapb
STPI OctaNE CoE Brochure.pdfSTPI OctaNE CoE Brochure.pdf
STPI OctaNE CoE Brochure.pdf
madhurjyapb14 views
Attacking IoT Devices from a Web Perspective - Linux Day by Simone Onofri
Attacking IoT Devices from a Web Perspective - Linux Day Attacking IoT Devices from a Web Perspective - Linux Day
Attacking IoT Devices from a Web Perspective - Linux Day
Simone Onofri16 views
Case Study Copenhagen Energy and Business Central.pdf by Aitana
Case Study Copenhagen Energy and Business Central.pdfCase Study Copenhagen Energy and Business Central.pdf
Case Study Copenhagen Energy and Business Central.pdf
Aitana16 views
handbook for web 3 adoption.pdf by Liveplex
handbook for web 3 adoption.pdfhandbook for web 3 adoption.pdf
handbook for web 3 adoption.pdf
Liveplex22 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely21 views

Realtime web2012

  • 1. Building Real-Time Web http://tinyurl.com/realtime2012 http:// Timothy Fitz .com CTO Canvas
  • 7. Talking to the browser High concurrency Scaling up 3 HARD PROBLEMS
  • 8. Talking to the browser • Short Polling • Long Polling • WebSocket • Flash Socket
  • 13. High Concurrency • Blocking I/O – Thread per process – Tops out at 200 to 1k connections • Non-blocking I/O – One process, one thread – 10k to 100k connections
  • 16. There is no apache for realtime
  • 17. Non-blocking I/O Servers • Python – Twisted – Tornado – gevent • Not python – Node.js – Erlang something
  • 18. Twisted • Pro – Can talk every protocol ever – Oldest and most widely used in production • Con – Overkill for web-only tasks – Not simple
  • 19. Tornado • Pro – Simple – Does HTTP stuff simply • Con – Might not interface with what you need • Confusing – You can run Tornado (HTTP layer) on top of Twisted (networking layer)
  • 20. gevent • Pro – Coroutines are a better model than callbacks – As such, very easy to write complicated logic • Con – Least well documented – Least consensus on best practices – New, uncertain about production readiness
  • 21. Node.js • Pro – Best documentation by far – Socket.IO abstracts away browser communication • Con – Can’t share logic between Django app – New, but has fairly large install base
  • 22. Erlang • Pro – Hands down best for complex realtime tasks – Forces you to think about concurrency/scale – Abstracts away the network – Old and reliable • Con – Forces you to think about concurrency/scale – Can’t share logic between Django app – High spin-up cost (functional, concurrency driven)
  • 23. Just one Frontend nodes x Backend nodes More architecture decisions! SCALING UP!
  • 24. Just one • Everything in memory • Django nodes talk directly to box • Spare for availability • Failover = realtime data loss – Make realtime 100% redundant
  • 25. Probably good enough! – WARNING: NAPKIN MATH – 10k daily visits * 10.0min avg visit = 70 average concurrent users – One box can easily be built out to handle 3-5k = Roughly 450k-700k daily visits
  • 26. Frontend nodes x Backend nodes • Frontend handle users / connections • Backend handles channels
  • 27. More architecture decisions! • In memory backend – Redis Pub/Sub – ZeroMQ – Roll your own • Persisted to Disk: – ActiveMQ – RabbitMQ – Amazon SQS
  • 28. Redis Pub/Sub • Simplest to setup • Simplest model • SUBSCRIBE channel_name • PUBLISH channel_name “Hello World!”
  • 29. ZeroMQ • Publish/Subscribe semantics • Request/Response • Push/Pull (round robin) • Extremely fast
  • 30. Roll your own • Same language as your frontend – (Twisted/Node/Whatever) • Only do this if you have per-channel business logic – You probably don’t. • Erlang maps really really well to this domain.
  • 31. Full Stack Services • REST APIs to push to the browser • http://pusher.com • http://beaconpush.com
  • 32. Canvas Amazon ELB Nginx + Twisted Redis
  • 33. Final Recommendations • Need python? Twisted • Don’t? Node.js/SocketIO • Need scale/reliability? Redis backend. • Complex? Going big? Erlang all the way.
  • 35. Further Reading • IMVU IMQ talk http://www.slideshare.net/JonWatte/message-queuing- on-a-large-scale-imvus-stateful-realtime-message-queue • Twilio talk on gevent + zeromq (given by Jeff Lindsay, highly recomended): http://www.twilio.com/conference/video/distributed-systems-with- gevent-and-zeromq • Last.fm scaling Eralng/Mochiweb to 1 million concurrent connections on one machine: http://www.metabrew.com/article/a-million-user-comet- application-with-mochiweb-part-1 • The original Comet blog post: http://infrequently.org/2006/03/comet-low- latency-data-for-the-browser/ • Django + Socket.IO + gevent: http://codysoyland.com/2011/feb/6/evented-django-part-one-socketio- and-gevent/

Editor's Notes

  1. Also known as Comet (in response to AJAX)And before that, under the umbrella of “DHTML” (throwback to the late 90s!)
  2. Latency often doesn’t matter at all (3-5s wouldn’t be noticed, for popular hashtags 1 minute wouldn’t make a difference)
  3. Chat (which is pubsub on steroids)Presence (the fact that you’re connected is important)Latency matters some, but you wouldn’t notice 1s of lag.
  4. Gaming, networked simulated physics / simulated spaces. Latency is critical in both directions (~200ms matters)
  5. Also a dozen other methods, and aggregate methods that have built-in fall back semantics.
  6. Supported absolutely everywhereIncredibly efficientIncredibly easy to implement, hard to get wrongRight for infrequent realtime, or tied to existing expensive operation (most common example: short poll Paypal/payment gateway for success confirmation)
  7. Works everywhere (desktop and mobile)Supports most use cases (twitter, etc)
  8. Requires flash support (user has it, no flashblock, desktop only for the most part)Bidirectional and binary.Bidirectional really only matters for realtime interactive apps (games, virtual spaces, motion is one of the few places where 200ms latency matters)Flash is dying, but if your app already requires (or if your UI is already in flash, hello vidya game) then this might be the best solution.
  9. Works on Chrome, FF, Safari, iOS mobile, IE10 previews. Coming to Android Mobile soon.Bidirectional, but UTF-8 (probably doesn’t matter)Very new (RFC hit “Proposed Standard” in Dec 2011, which means the spec is solidified. “Internet Standard” is then next step, and reserved for two independent interoperable implementations, very close)Great but you’ll probably have to support fallback for a while 
  10. Super simplifying, lots of options exist including hybrids.Often run one non-blocking process per core (if you have to scale to multiple machines, using the same strategy for multiple processes is trivial)
  11. Okay this is kind of a lie, there are hacky ways but you lose most of what makes Django, Django: sessions, users, auth, ORM, and most 3rd party libraries
  12. There is no consensus. There are some good python options. There are a LOT of options I’m not even mentioning, almost every language has two or three non-blocking I/O webservers. Python might be important, especially if you have logic you want to reuse between your Django application and your non-blocking I/O app
  13. Can have two for redundancy