SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Implementing real time web
                          applications with Django
                                 Kristian Øllegaard




                                         1
onsdag den 6. juni 12
About me


                  •     Software Developer/System Administrator at Divio

                  •     Django since 0.96

                  •     Danish, lived in Zurich 1,5 year



                                                                                            @oellegaard
                                                                           github.com/KristianOellegaard
                                                           2
onsdag den 6. juni 12
Why real time?

                  •     Better user experience

                  •     More options in front end

                  •     Make the web feel like native apps

                  •     Showing live data.

                  •     Collaboration is much easier.

                                                                              @oellegaard
                                                             github.com/KristianOellegaard
                                                         3
onsdag den 6. juni 12
Finding the right tool
                  •     Criteria's

                        •   Use websockets, but have fallbacks

                        •   Good browser support (incl. old IE)

                        •   Should be usable from python

                        •   Does not require extensive changes in frontend

                        •   “As fast as it can be”
                                                                                              @oellegaard
                                                                             github.com/KristianOellegaard
                                                           4
onsdag den 6. juni 12
The tools you want


                        Node.js + Socket.io

                                                                @oellegaard
                                               github.com/KristianOellegaard
                                  5
onsdag den 6. juni 12
The tools you want


                                 Node.js + Socket.io
                        (well, we don’t want this, but socket.io needs it)




                                                                                                  @oellegaard
                                                                                 github.com/KristianOellegaard
                                                                             5
onsdag den 6. juni 12
The tools you want
                  •     Node.js

                        •   Built on Chrome's JavaScript runtime

                        •   Uses an event-driven, non-blocking I/O model

                  •     Socket.io

                        •   One interface for all transport methods (sockets, polling, etc.)

                        •   Compatible with almost everything
                                                                                                                @oellegaard
                                                                                               github.com/KristianOellegaard
                                                            6
onsdag den 6. juni 12
Why not implement it in Python?

                  •     Already active community

                  •     Can be used from python without too much trouble

                  •     Most people know very basic javascript

                  •     More importantly, frontend engineers, knows javascript and can
                        therefore contribute to the different browser-specific
                        implementations.

                                                                                                          @oellegaard
                                                                                         github.com/KristianOellegaard
                                                        7
onsdag den 6. juni 12
Using redis for cross-language
                                communication
                  •     Support for many datatypes

                  •     Can be used both as storage and as a queue

                  •     Implemented in many different languages

                  •     For the usage in this talk, any other queue could have been used as
                        well.

                                                                                                          @oellegaard
                                                                                         github.com/KristianOellegaard
                                                         8
onsdag den 6. juni 12
Basic concept
                  •     Something happens, the user
                                                                                  Redis
                        must be notified in real time               publish                publish




                        •
                                                                             subscribe

                            From e.g. django we insert the
                                                                                           E.g.
                            new value into the queue             Django         Node.js
                                                                                          Celery

                        •   Node.js listens on the queue                     subscribe



                            and emits any content directly                     Browser
                            to the browser via socket.io

                        •   This is btw. very fast!
                                                                                                                     @oellegaard
                                                                                                    github.com/KristianOellegaard
                                                             9
onsdag den 6. juni 12
Sample node.js app

                        var io = require('socket.io').listen(8001);
                        var redis = require('redis').createClient();

                        redis.psubscribe("socketio_*"); // Could be any pattern

                        io.sockets.on('connection', function (socket) {
                            redis.on('pmessage', function(pattern, channel, key){
                                socket.emit(channel, key);
                            });
                        });



                                                                                                     @oellegaard
                                                                                    github.com/KristianOellegaard
                                                          10
onsdag den 6. juni 12
Sample HTML/JS

                        <script src="http://localhost:8001/socket.io/socket.io.js"></script>
                        <script>
                          var socket = io.connect('http://localhost:8001/');
                          socket.on('socketio_news', function (data) {
                            console.log(data);
                          });
                        </script>




                                                                                                            @oellegaard
                                                                                           github.com/KristianOellegaard
                                                          11
onsdag den 6. juni 12
Sample usage from Python


                        import redis
                        import json
                        redis_subscribe = redis.StrictRedis()
                        redis_subscribe.publish("socketio_news", json.dumps({
                           'title': 'Djangocon 2012',
                        }))




                                                                                                 @oellegaard
                                                                                github.com/KristianOellegaard
                                                          12
onsdag den 6. juni 12
Short demo




                                                      @oellegaard
                                     github.com/KristianOellegaard
                            13
onsdag den 6. juni 12
Hosting socket.io

                  •     Nginx does not support websockets!

                  •     Needs its own app, if hosted on an application cloud (e.g. heroku)

                  •     Recommended to expose the node server directly

                        •   But hey, it’s node.js, it scales!


                                                                                                          @oellegaard
                                                                                         github.com/KristianOellegaard
                                                                14
onsdag den 6. juni 12
Can I use this today?


                  •     Yes

                  •     But, please don’t




                                                                             @oellegaard
                                                            github.com/KristianOellegaard
                                              15
onsdag den 6. juni 12
Client Authentication

                  •     Socket.io handles authentication from node -> client

                  •     Currently no authentication between django and node.

                  •     Could possibly be solved by storing your sessions in redis and
                        checking them on connection.


                                                                                                          @oellegaard
                                                                                         github.com/KristianOellegaard
                                                        16
onsdag den 6. juni 12
Notes


                  •     Concept should work with any language/framework

                        •   E.g. communicating between ruby and python




                                                                                           @oellegaard
                                                                          github.com/KristianOellegaard
                                                         17
onsdag den 6. juni 12
Questions?

                        http://kristian.io
                         @oellegaard


                                                              @oellegaard
                                             github.com/KristianOellegaard
                                18
onsdag den 6. juni 12

Weitere ähnliche Inhalte

Was ist angesagt?

Zabbix - an important part of your IT infrastructure
Zabbix - an important part of your IT infrastructureZabbix - an important part of your IT infrastructure
Zabbix - an important part of your IT infrastructure
Arvids Godjuks
 

Was ist angesagt? (20)

Dcjq node.js presentation
Dcjq node.js presentationDcjq node.js presentation
Dcjq node.js presentation
 
Owasp tools - OWASP Serbia
Owasp tools - OWASP SerbiaOwasp tools - OWASP Serbia
Owasp tools - OWASP Serbia
 
Vladimir Ulogov - Beyond the Loadable Module
Vladimir Ulogov - Beyond the Loadable ModuleVladimir Ulogov - Beyond the Loadable Module
Vladimir Ulogov - Beyond the Loadable Module
 
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAPVirtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
Virtual Security Lab Setup - OWASP Broken Web Apps, Webgoat, & ZAP
 
OWASP 2012 AppSec Dublin ZAP Intro
OWASP 2012 AppSec Dublin ZAP IntroOWASP 2012 AppSec Dublin ZAP Intro
OWASP 2012 AppSec Dublin ZAP Intro
 
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
OWASP 2013 AppSec EU Hamburg - ZAP InnovationsOWASP 2013 AppSec EU Hamburg - ZAP Innovations
OWASP 2013 AppSec EU Hamburg - ZAP Innovations
 
Csp and http headers
Csp and http headersCsp and http headers
Csp and http headers
 
WebRTC & Asterisk 11
WebRTC & Asterisk 11WebRTC & Asterisk 11
WebRTC & Asterisk 11
 
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
Dimitri Bellini and Pietro Antonacci - Manage Zabbix Proxies in Remote Networ...
 
Zabbix conference2015 daisukeikeda
Zabbix conference2015 daisukeikedaZabbix conference2015 daisukeikeda
Zabbix conference2015 daisukeikeda
 
Zabbix - an important part of your IT infrastructure
Zabbix - an important part of your IT infrastructureZabbix - an important part of your IT infrastructure
Zabbix - an important part of your IT infrastructure
 
OWASP 2013 APPSEC USA Talk - OWASP ZAP
OWASP 2013 APPSEC USA Talk - OWASP ZAPOWASP 2013 APPSEC USA Talk - OWASP ZAP
OWASP 2013 APPSEC USA Talk - OWASP ZAP
 
OWASP 2013 EU Tour Amsterdam ZAP Intro
OWASP 2013 EU Tour Amsterdam ZAP IntroOWASP 2013 EU Tour Amsterdam ZAP Intro
OWASP 2013 EU Tour Amsterdam ZAP Intro
 
JavaOne 2014 Security Testing for Developers using OWASP ZAP
JavaOne 2014 Security Testing for Developers using OWASP ZAPJavaOne 2014 Security Testing for Developers using OWASP ZAP
JavaOne 2014 Security Testing for Developers using OWASP ZAP
 
AWS Survival Guide
AWS Survival GuideAWS Survival Guide
AWS Survival Guide
 
OWASP 2014 AppSec EU ZAP Advanced Features
OWASP 2014 AppSec EU ZAP Advanced FeaturesOWASP 2014 AppSec EU ZAP Advanced Features
OWASP 2014 AppSec EU ZAP Advanced Features
 
You'll Never Look at Developer Support the Same Way Again
You'll Never Look at Developer Support the Same Way AgainYou'll Never Look at Developer Support the Same Way Again
You'll Never Look at Developer Support the Same Way Again
 
OWASP 2013 APPSEC USA ZAP Hackathon
OWASP 2013 APPSEC USA ZAP HackathonOWASP 2013 APPSEC USA ZAP Hackathon
OWASP 2013 APPSEC USA ZAP Hackathon
 
Florian Koch - Monitoring CoreOS with Zabbix
Florian Koch - Monitoring CoreOS with ZabbixFlorian Koch - Monitoring CoreOS with Zabbix
Florian Koch - Monitoring CoreOS with Zabbix
 
LasCon 2014 DevOoops
LasCon 2014 DevOoops LasCon 2014 DevOoops
LasCon 2014 DevOoops
 

Ähnlich wie Implementing real time web applications with Django

Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
kennethaliu
 
Gradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypesGradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypes
Strannik_2013
 
Foundation Comparison
Foundation ComparisonFoundation Comparison
Foundation Comparison
Jody Garnett
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
rsebbe
 
SF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSSSF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSS
Justin Ryan
 

Ähnlich wie Implementing real time web applications with Django (20)

How we build project for Open Source
How we build project for Open SourceHow we build project for Open Source
How we build project for Open Source
 
Mortar: Hadoop-as-a-Service + Open Source Framework | AWS re: Invent public …
Mortar: Hadoop-as-a-Service + Open Source Framework | AWS re: Invent public …Mortar: Hadoop-as-a-Service + Open Source Framework | AWS re: Invent public …
Mortar: Hadoop-as-a-Service + Open Source Framework | AWS re: Invent public …
 
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
Modularizing your Grails Application with Private Plugins - SpringOne 2GX 2012
 
Clojurescript slides
Clojurescript slidesClojurescript slides
Clojurescript slides
 
Intro to Python for C# Developers
Intro to Python for C# DevelopersIntro to Python for C# Developers
Intro to Python for C# Developers
 
13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications13 practical tips for writing secure golang applications
13 practical tips for writing secure golang applications
 
Introducing Hydra – An Open Source Document Processing Framework
Introducing Hydra – An Open Source Document Processing FrameworkIntroducing Hydra – An Open Source Document Processing Framework
Introducing Hydra – An Open Source Document Processing Framework
 
Evolution of NuGet
Evolution of NuGetEvolution of NuGet
Evolution of NuGet
 
IoT is Something to Figure Out
IoT is Something to Figure OutIoT is Something to Figure Out
IoT is Something to Figure Out
 
Open sourcery
Open sourceryOpen sourcery
Open sourcery
 
Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?Que nos espera a los ALM Dudes para el 2013?
Que nos espera a los ALM Dudes para el 2013?
 
Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...Generalization in Auto-Testing. How we put what we had into new Technological...
Generalization in Auto-Testing. How we put what we had into new Technological...
 
Gradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypesGradle 2.Breaking stereotypes
Gradle 2.Breaking stereotypes
 
Why use Go for web development?
Why use Go for web development?Why use Go for web development?
Why use Go for web development?
 
Rapid Application Development on Google App Engine for Java
Rapid Application Development on Google App Engine for JavaRapid Application Development on Google App Engine for Java
Rapid Application Development on Google App Engine for Java
 
Foundation Comparison
Foundation ComparisonFoundation Comparison
Foundation Comparison
 
GoLang - Why It Matters
GoLang -  Why It MattersGoLang -  Why It Matters
GoLang - Why It Matters
 
Orthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable CodeOrthogonality: A Strategy for Reusable Code
Orthogonality: A Strategy for Reusable Code
 
javerosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparisonjaverosmx-2015-marzo-groovy-java8-comparison
javerosmx-2015-marzo-groovy-java8-comparison
 
SF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSSSF Gradle Meetup - Netflix OSS
SF Gradle Meetup - Netflix OSS
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Implementing real time web applications with Django

  • 1. Implementing real time web applications with Django Kristian Øllegaard 1 onsdag den 6. juni 12
  • 2. About me • Software Developer/System Administrator at Divio • Django since 0.96 • Danish, lived in Zurich 1,5 year @oellegaard github.com/KristianOellegaard 2 onsdag den 6. juni 12
  • 3. Why real time? • Better user experience • More options in front end • Make the web feel like native apps • Showing live data. • Collaboration is much easier. @oellegaard github.com/KristianOellegaard 3 onsdag den 6. juni 12
  • 4. Finding the right tool • Criteria's • Use websockets, but have fallbacks • Good browser support (incl. old IE) • Should be usable from python • Does not require extensive changes in frontend • “As fast as it can be” @oellegaard github.com/KristianOellegaard 4 onsdag den 6. juni 12
  • 5. The tools you want Node.js + Socket.io @oellegaard github.com/KristianOellegaard 5 onsdag den 6. juni 12
  • 6. The tools you want Node.js + Socket.io (well, we don’t want this, but socket.io needs it) @oellegaard github.com/KristianOellegaard 5 onsdag den 6. juni 12
  • 7. The tools you want • Node.js • Built on Chrome's JavaScript runtime • Uses an event-driven, non-blocking I/O model • Socket.io • One interface for all transport methods (sockets, polling, etc.) • Compatible with almost everything @oellegaard github.com/KristianOellegaard 6 onsdag den 6. juni 12
  • 8. Why not implement it in Python? • Already active community • Can be used from python without too much trouble • Most people know very basic javascript • More importantly, frontend engineers, knows javascript and can therefore contribute to the different browser-specific implementations. @oellegaard github.com/KristianOellegaard 7 onsdag den 6. juni 12
  • 9. Using redis for cross-language communication • Support for many datatypes • Can be used both as storage and as a queue • Implemented in many different languages • For the usage in this talk, any other queue could have been used as well. @oellegaard github.com/KristianOellegaard 8 onsdag den 6. juni 12
  • 10. Basic concept • Something happens, the user Redis must be notified in real time publish publish • subscribe From e.g. django we insert the E.g. new value into the queue Django Node.js Celery • Node.js listens on the queue subscribe and emits any content directly Browser to the browser via socket.io • This is btw. very fast! @oellegaard github.com/KristianOellegaard 9 onsdag den 6. juni 12
  • 11. Sample node.js app var io = require('socket.io').listen(8001); var redis = require('redis').createClient(); redis.psubscribe("socketio_*"); // Could be any pattern io.sockets.on('connection', function (socket) {     redis.on('pmessage', function(pattern, channel, key){         socket.emit(channel, key);     }); }); @oellegaard github.com/KristianOellegaard 10 onsdag den 6. juni 12
  • 12. Sample HTML/JS <script src="http://localhost:8001/socket.io/socket.io.js"></script> <script>   var socket = io.connect('http://localhost:8001/');   socket.on('socketio_news', function (data) {     console.log(data);   }); </script> @oellegaard github.com/KristianOellegaard 11 onsdag den 6. juni 12
  • 13. Sample usage from Python import redis import json redis_subscribe = redis.StrictRedis() redis_subscribe.publish("socketio_news", json.dumps({    'title': 'Djangocon 2012', })) @oellegaard github.com/KristianOellegaard 12 onsdag den 6. juni 12
  • 14. Short demo @oellegaard github.com/KristianOellegaard 13 onsdag den 6. juni 12
  • 15. Hosting socket.io • Nginx does not support websockets! • Needs its own app, if hosted on an application cloud (e.g. heroku) • Recommended to expose the node server directly • But hey, it’s node.js, it scales! @oellegaard github.com/KristianOellegaard 14 onsdag den 6. juni 12
  • 16. Can I use this today? • Yes • But, please don’t @oellegaard github.com/KristianOellegaard 15 onsdag den 6. juni 12
  • 17. Client Authentication • Socket.io handles authentication from node -> client • Currently no authentication between django and node. • Could possibly be solved by storing your sessions in redis and checking them on connection. @oellegaard github.com/KristianOellegaard 16 onsdag den 6. juni 12
  • 18. Notes • Concept should work with any language/framework • E.g. communicating between ruby and python @oellegaard github.com/KristianOellegaard 17 onsdag den 6. juni 12
  • 19. Questions? http://kristian.io @oellegaard @oellegaard github.com/KristianOellegaard 18 onsdag den 6. juni 12