SlideShare a Scribd company logo
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/

More Related Content

PPTX
EhTrace -- RoP Hooks
Shane Macaulay
 
PPT
Resumable File Upload API using GridFS and TUS
khangtoh
 
PPT
Tus.io presentation for iOS devscout meetup
khangtoh
 
PDF
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PHP Conference Argentina
 
PDF
tus.io – Resumable file uploads for web and mobile apps by Felix Geisendörfer
Codemotion
 
PPTX
Stabilizing SE Build - Selenium conf 2013
dimakovalenko
 
PDF
SwampDragon presentation: The Copenhagen Django Meetup Group
Ernest Jumbe
 
PDF
Asynchronous Programming in Kotlin with Coroutines
Tobias Schürg
 
EhTrace -- RoP Hooks
Shane Macaulay
 
Resumable File Upload API using GridFS and TUS
khangtoh
 
Tus.io presentation for iOS devscout meetup
khangtoh
 
2013 - Igor Sysoev - NGINx: origen, evolución y futuro - PHP Conference Argen...
PHP Conference Argentina
 
tus.io – Resumable file uploads for web and mobile apps by Felix Geisendörfer
Codemotion
 
Stabilizing SE Build - Selenium conf 2013
dimakovalenko
 
SwampDragon presentation: The Copenhagen Django Meetup Group
Ernest Jumbe
 
Asynchronous Programming in Kotlin with Coroutines
Tobias Schürg
 

What's hot (20)

PPTX
Rabbits, indians and... Symfony meets queueing brokers
Gaetano Giunta
 
KEY
Ruby Concurrency Realities
Mike Subelsky
 
PDF
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Grant Norwood
 
KEY
Zero mq logs
Tomas Doran
 
PDF
Perconalive feb-2011-share
mdcallag
 
KEY
Hybrid concurrency patterns
Kyle Drake
 
PDF
STAQ Development Manual (Redacted)
Mike Subelsky
 
PDF
Get Off My Thread! - keep your UI super-responsive
DroidConTLV
 
PPTX
Making Symfony Services async with RabbitMq (and more Symfony)
Gaetano Giunta
 
PDF
Big Data! Great! Now What? #SymfonyCon 2014
Ricard Clau
 
PPTX
My month with Ruby
alextomovski
 
PDF
Stackato v3
Jonas Brømsø
 
PDF
Ratpack for Real
TomAkehurst
 
PDF
Riak at Posterous
capotej
 
PDF
Dark Fairytales from a Phisherman
Michele Orru
 
PPTX
Why internal pen tests are still fun
pyschedelicsupernova
 
ODP
Some dope on Zope (Jan 2002, Bangalore LUG)
Kiran Jonnalagadda
 
PDF
What's new in Symfony3
Yuki MAEJIMA
 
PPTX
Designing a Docker Stack for Symfony apps: lessons learned
Gaetano Giunta
 
PDF
Woo: Writing a fast web server
fukamachi
 
Rabbits, indians and... Symfony meets queueing brokers
Gaetano Giunta
 
Ruby Concurrency Realities
Mike Subelsky
 
Cluster Fudge: Recipes for WordPress in the Cloud (WordCamp Austin 2014 Speaker)
Grant Norwood
 
Zero mq logs
Tomas Doran
 
Perconalive feb-2011-share
mdcallag
 
Hybrid concurrency patterns
Kyle Drake
 
STAQ Development Manual (Redacted)
Mike Subelsky
 
Get Off My Thread! - keep your UI super-responsive
DroidConTLV
 
Making Symfony Services async with RabbitMq (and more Symfony)
Gaetano Giunta
 
Big Data! Great! Now What? #SymfonyCon 2014
Ricard Clau
 
My month with Ruby
alextomovski
 
Stackato v3
Jonas Brømsø
 
Ratpack for Real
TomAkehurst
 
Riak at Posterous
capotej
 
Dark Fairytales from a Phisherman
Michele Orru
 
Why internal pen tests are still fun
pyschedelicsupernova
 
Some dope on Zope (Jan 2002, Bangalore LUG)
Kiran Jonnalagadda
 
What's new in Symfony3
Yuki MAEJIMA
 
Designing a Docker Stack for Symfony apps: lessons learned
Gaetano Giunta
 
Woo: Writing a fast web server
fukamachi
 
Ad

Similar to Realtime web2012 (20)

PDF
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Nathan O'Hanlon
 
KEY
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
PDF
Scaling with Symfony - PHP UK
Ricard Clau
 
PPTX
Life Beyond Rails: Creating Cross Platform Ruby Apps
Tristan Gomez
 
PDF
The State of WebSockets in Django
Rami Sayar
 
PDF
From a student to an apache committer practice of apache io tdb
jixuan1989
 
KEY
High performance network programming on the jvm oscon 2012
Erik Onnen
 
PDF
Distributed "Web Scale" Systems
Ricardo Vice Santos
 
KEY
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake
 
PDF
NullMQ @ PDX
Jeff Lindsay
 
PDF
Modern software architectures - PHP UK Conference 2015
Ricard Clau
 
PDF
EKON27-FrameworksTuning.pdf
Arnaud Bouchez
 
PPTX
Be faster then rabbits
Vladislav Bauer
 
PDF
Lares from LOW to PWNED
Chris Gates
 
PDF
Three years of OFELIA - taking stock
FIBRE Testbed
 
PDF
John adams talk cloudy
John Adams
 
PDF
Vert.x introduction
GR8Conf
 
PDF
Phoenix for Rubyists
Doug Goldie
 
Html5 web sockets - Brad Drysdale - London Web 2011-10-20
Nathan O'Hanlon
 
Messaging, interoperability and log aggregation - a new framework
Tomas Doran
 
Scaling with Symfony - PHP UK
Ricard Clau
 
Life Beyond Rails: Creating Cross Platform Ruby Apps
Tristan Gomez
 
The State of WebSockets in Django
Rami Sayar
 
From a student to an apache committer practice of apache io tdb
jixuan1989
 
High performance network programming on the jvm oscon 2012
Erik Onnen
 
Distributed "Web Scale" Systems
Ricardo Vice Santos
 
Fast, concurrent ruby web applications with EventMachine and EM::Synchrony
Kyle Drake
 
NullMQ @ PDX
Jeff Lindsay
 
Modern software architectures - PHP UK Conference 2015
Ricard Clau
 
EKON27-FrameworksTuning.pdf
Arnaud Bouchez
 
Be faster then rabbits
Vladislav Bauer
 
Lares from LOW to PWNED
Chris Gates
 
Three years of OFELIA - taking stock
FIBRE Testbed
 
John adams talk cloudy
John Adams
 
Vert.x introduction
GR8Conf
 
Phoenix for Rubyists
Doug Goldie
 
Ad

More from Timothy Fitz (12)

PDF
Good hypothesis testing is surprising!
Timothy Fitz
 
PDF
Continuous Deployment: Beyond Continuous Delivery
Timothy Fitz
 
PPT
Gdc 2010 architecture final slideshare edition
Timothy Fitz
 
PPTX
Scaling Up Continuous Deployment
Timothy Fitz
 
PPTX
The Hard Problems of Continuous Deployment
Timothy Fitz
 
PPTX
Continuous Deployment
Timothy Fitz
 
PPTX
Continuous Deployment
Timothy Fitz
 
PPTX
Shdh
Timothy Fitz
 
KEY
Socket.io
Timothy Fitz
 
PPTX
Shdh
Timothy Fitz
 
PPTX
Continuous Deployment
Timothy Fitz
 
PPT
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Timothy Fitz
 
Good hypothesis testing is surprising!
Timothy Fitz
 
Continuous Deployment: Beyond Continuous Delivery
Timothy Fitz
 
Gdc 2010 architecture final slideshare edition
Timothy Fitz
 
Scaling Up Continuous Deployment
Timothy Fitz
 
The Hard Problems of Continuous Deployment
Timothy Fitz
 
Continuous Deployment
Timothy Fitz
 
Continuous Deployment
Timothy Fitz
 
Socket.io
Timothy Fitz
 
Continuous Deployment
Timothy Fitz
 
Just In Time Scalability Agile Methods To Support Massive Growth Presentation
Timothy Fitz
 

Recently uploaded (20)

PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PDF
Doc9.....................................
SofiaCollazos
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Doc9.....................................
SofiaCollazos
 
The Future of Artificial Intelligence (AI)
Mukul
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 

Realtime web2012

  • 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

  • #3: Also known as Comet (in response to AJAX)And before that, under the umbrella of “DHTML” (throwback to the late 90s!)
  • #4: Latency often doesn’t matter at all (3-5s wouldn’t be noticed, for popular hashtags 1 minute wouldn’t make a difference)
  • #5: 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.
  • #6: Gaming, networked simulated physics / simulated spaces. Latency is critical in both directions (~200ms matters)
  • #9: Also a dozen other methods, and aggregate methods that have built-in fall back semantics.
  • #10: 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)
  • #11: Works everywhere (desktop and mobile)Supports most use cases (twitter, etc)
  • #12: 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.
  • #13: 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 
  • #14: 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)
  • #16: 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
  • #18: 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
  • #25: Can have two for redundancy