SlideShare a Scribd company logo
1 of 40
Download to read offline
Advanced Django
Architecture
Rami Sayar - @ramisayar
Technical Evangelist
Microsoft Canada
Advanced Scalable
Django Architecture
Rami Sayar - @ramisayar
Technical Evangelist
Microsoft Canada
Agenda
•  Advanced Django Techniques & Patterns
•  Structuring Complex Applications
•  Scaling Django Applications
•  Django Applications in Production
CONFOO - @RAMISAYAR
What is a production web app?
•  Django is surrounded by tons
of applications, services and
code in production.
•  Advanced Django architecture
is needed to support Django
in production without failing
hard.
CONFOO - @RAMISAYAR
Load Balancing Django
CONFOO - @RAMISAYAR
Load Balancing
•  Load balancing Django improves the performance and reliability
by distributing traffic.
•  Becomes an interesting problem when you have to consider:
•  SSL Termination
•  Sticky Sessions?
•  WebSockets?
CONFOO - @RAMISAYAR
Load Balancing = Django + HAProxy + SSL
•  HAProxy gained native SSL support in HAProxy 1.5.x => June
2014!
•  SSL Termination:
•  Fairly straightforward to set up HAProxy.
•  Read: How To Implement SSL Termination With HAProxy
CONFOO - @RAMISAYAR
Load Balancing Proxying & Remote Addr
class SetRemoteAddrFromForwardedFor(object):
def process_request(self, request):
try:
real_ip = request.META['HTTP_X_FORWARDED_FOR']
except KeyError:
pass
else:
# HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs.
# Take just the first one.
real_ip = real_ip.split(",")[0]
request.META['REMOTE_ADDR'] = real_ip
CONFOO - @RAMISAYAR
Azure Traffic Manager
•  High Performance Load
Balancer + DNS Support.
•  Sticky Sessions don’t exist.
•  HTTPS Supported.
CONFOO - @RAMISAYAR
Caching Django
CONFOO - @RAMISAYAR
Caching = Django + Varnish
•  Varnish has a tendency to just cache EVERYTHING which can
be frustrating for the User, unless you set it up properly.
•  Varnish does not cache content & cookies.
•  Varnish and Django CSRF protection gotcha.
•  Varnish does not deal with HTTPS (hence the need of HAProxy
in front of Varnish).
CONFOO - @RAMISAYAR
Caching = Django + Varnish
•  Django-Varnish – “It allows you to monitor certain models and
when they are updated, Django Varnish will purge the model's
absolute_url on your frontend(s). This ensures that object detail
pages are served blazingly fast and are always up to date.”
•  https://github.com/justquick/django-varnish
•  Project Idea: Deeper Django/Varnish integration.
CONFOO - @RAMISAYAR
Caching = Django + Varnish
•  https://www.varnish-cache.org/
•  http://www.isvarnishworking.com/
•  http://yml-blog.blogspot.ca/2010/01/esi-using-varnish-and-
django.html
•  http://chase-seibert.github.io/blog/2011/09/23/varnish-caching-
for-unauthenticated-django-views.html
•  http://blog.bigdinosaur.org/adventures-in-varnish/
•  http://www.nedproductions.biz/wiki/a-perfected-varnish-reverse-
caching-proxy-vcl-script
CONFOO - @RAMISAYAR
Serving Django
CONFOO - @RAMISAYAR
Web Server = Django + Apache
•  Forced to use Apache? Your options:
•  mod_python (No)
•  mod_wsgi (Yes)
•  FastCGI (Deprecated since 1.7)
•  Phusion Passenger (Yes)
CONFOO - @RAMISAYAR
Web Server = Django + Apache
•  mod_wsgi
•  Decent performance on the Apache side.
•  You can setup Apache any way you like.
•  You can setup mod_wsgi to use virtualenv.
CONFOO - @RAMISAYAR
Web Server = Django + Apache
import os, sys, site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/.virtualenvs/myprojectenv/local/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/django_projects/MyProject')
sys.path.append('/home/django_projects/MyProject/myproject')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
# Activate your virtual env
activate_env=os.path.expanduser("~/.virtualenvs/myprojectenv/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
CONFOO - @RAMISAYAR
Web Server = Django + Alternatives (aka. Nginx)
•  Nginx + uWSGI
[uwsgi]
touch-reload = /tmp/newproject
socket = 127.0.0.1:3031
workers = 2
chdir = /srv/newproject
env = DJANGO_SETTINGS_MODULE=newproject.settings
module = django.core.handlers.wsgi:WSGIHander()
CONFOO - @RAMISAYAR
Web Server = Django + Alternatives (aka. Gunicorn)
•  Nginx & Gunicorn
•  In theory, you should use Nginx as a reverse proxy here, to serve static
files if you’re not uploading everything to a CDN or a separate media
server. If you are, you can use HAProxy and Gunicorn as a standalone
webserver, one less dependency to care about.
•  Install Gunicorn directly inside your virtual environment.
•  Use Gaffer to monitor the Gunicorn.
CONFOO - @RAMISAYAR
Web Server - References
•  http://blog.kgriffs.com/2012/12/18/uwsgi-vs-gunicorn-vs-node-
benchmarks.html
CONFOO - @RAMISAYAR
REST APIs & Django
CONFOO - @RAMISAYAR
Use Django REST Framework!
Django REST Framework vs Django Tasty Pie
CONFOO - @RAMISAYAR
Cache & Django
CONFOO - @RAMISAYAR
Caching in Production
•  Caching – Django has multiple options:
•  Redis. Make sure you use Hiredis and django-redis-cache. Use a
hosted Redis Cache (Azure, AWS, etc).
•  Memcached. Make sure you use pylibmc and not python-memcached,
better performance with the C library.
•  SSL still matters.
CONFOO - @RAMISAYAR
Azure Redis Cache
CONFOO - @RAMISAYAR
Logging Django
CONFOO - @RAMISAYAR
Logging in Production
•  Logstash
•  Collect logs, parse them, and store them for later use.
•  Free and open source.
•  Set it up with Redis.
CONFOO - @RAMISAYAR
Logging in Production – Use Python-Logstash
LOGGING = {
'handlers': {
'logstash': {
'level': 'DEBUG',
'class': 'logstash.LogstashHandler',
'host': 'localhost',
'port': 5959, # Default value: 5959
'version': 1, # Version of logstash event schema. Default value: 0 (for backward
compatibility of the library)
'message_type': 'logstash', # 'type' field in logstash message. Default value: 'logstash'.
'tags': ['tag1', 'tag2'], # list of tags. Default: None.
},
},
CONFOO - @RAMISAYAR
Logging in Production – Use Python-Logstash
'loggers': {
'django.request': {
'handlers': ['logstash'],
'level': 'DEBUG',
'propagate': True,
},
},
}
CONFOO - @RAMISAYAR
Logging in Production – Using Sentry
•  Realtime event logging and aggregation platform.
•  Specialize in monitoring exceptions and errors.
•  https://github.com/getsentry/sentry
CONFOO - @RAMISAYAR
PostgreSQL in Production
CONFOO - @RAMISAYAR
PostgreSQL in Production – pgpool & slony
•  PostgreSQL 9+ has streaming replication assuming you’re
running identical databases with identical version on identical
architectures (not really an issue).
•  If not using the Streaming Replication feature (WAL), you’ll want
to use either pgpool or slony to scale your PostgreSQL
database across multiple machines.
•  Use Slony if you want master-slave-peer replication.
•  Use pgpool or pgbouncer for connection pooling. Pgbouncer only does
connection pooling.
CONFOO - @RAMISAYAR
Async Tasks & Django
CONFOO - @RAMISAYAR
Async Tasks – Celery
•  Use Celery for Asynchronous Tasks
•  Use Celery with Redis and store results in Django ORM
•  RQ is an alternative for distributing tasks. (Based on Redis)
Read:
http://www.caktusgroup.com/blog/2014/09/29/celery-production/
CONFOO - @RAMISAYAR
On Redis
•  Redis is extremely popular as an easy and simple publish-
subscribe.
•  Redis is very particular about memory. Running out of memory
in Redis -> CRASH AND BURN!
•  If you don’t have enough memory in your VM to run Redis
Cache -> Change your approach, use Apache Kafka.
CONFOO - @RAMISAYAR
Tips & Techniques
•  Don’t forget:
•  Turn off Debug Mode
•  Turn off Template Debug Mode
•  Use different Django Settings Modules depending on the role
and environment you are in through environment variables by
setting “DJANGO_SETTINGS_MODULE”.
CONFOO - @RAMISAYAR
What did we learn?
•  Scaling Django Architectures
•  Most of the work surrounds Django
•  Minimal changes to your django app for the most part.
CONFOO - @RAMISAYAR
Thank You! Questions?
Follow @ramisayar
CONFOO - @RAMISAYAR
Resources
•  http://blog.disqus.com/post/62187806135/scaling-django-to-8-
billion-page-views
•  http://engineering.hackerearth.com/2013/10/07/scaling-
database-with-django-and-haproxy/
•  http://www.djangobook.com/en/2.0/chapter12.html
•  https://www.digitalocean.com/community/tutorials/how-to-
implement-ssl-termination-with-haproxy-on-ubuntu-14-04
•  https://docs.djangoproject.com/en/1.7/topics/security/
•  https://www.digitalocean.com/community/tutorials/how-to-scale-
django-beyond-the-basics
CONFOO - @RAMISAYAR
©2013	
  Microso-	
  Corpora1on.	
  All	
  rights	
  reserved.	
  Microso-,	
  Windows,	
  Office,	
  Azure,	
  System	
  Center,	
  Dynamics	
  and	
  other	
  product	
  names	
  are	
  or	
  may	
  be	
  registered	
  trademarks	
  and/or	
  trademarks	
  in	
  the	
  
U.S.	
  and/or	
  other	
  countries.	
  The	
  informa1on	
  herein	
  is	
  for	
  informa1onal	
  purposes	
  only	
  and	
  represents	
  the	
  current	
  view	
  of	
  Microso-	
  Corpora1on	
  as	
  of	
  the	
  date	
  of	
  this	
  presenta1on.	
  Because	
  Microso-	
  
must	
  respond	
  to	
  changing	
  market	
  condi1ons,	
  it	
  should	
  not	
  be	
  interpreted	
  to	
  be	
  a	
  commitment	
  on	
  the	
  part	
  of	
  Microso-,	
  and	
  Microso-	
  cannot	
  guarantee	
  the	
  accuracy	
  of	
  any	
  informa1on	
  provided	
  a-er	
  
the	
  date	
  of	
  this	
  presenta1on.	
  MICROSOFT	
  MAKES	
  NO	
  WARRANTIES,	
  EXPRESS,	
  IMPLIED	
  OR	
  STATUTORY,	
  AS	
  TO	
  THE	
  INFORMATION	
  IN	
  THIS	
  PRESENTATION.	
  

More Related Content

What's hot

Common issues with Apache Kafka® Producer
Common issues with Apache Kafka® ProducerCommon issues with Apache Kafka® Producer
Common issues with Apache Kafka® Producerconfluent
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache CamelClaus Ibsen
 
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요Jo Hoon
 
Introduction to Python Asyncio
Introduction to Python AsyncioIntroduction to Python Asyncio
Introduction to Python AsyncioNathan Van Gheem
 
이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정Arawn Park
 
Apache Flink and what it is used for
Apache Flink and what it is used forApache Flink and what it is used for
Apache Flink and what it is used forAljoscha Krettek
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90minsLarry Cai
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX, Inc.
 
Amazon EC2 Instance Types.pptx
Amazon EC2 Instance Types.pptxAmazon EC2 Instance Types.pptx
Amazon EC2 Instance Types.pptxRomitSingh17
 
NGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEANGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEANGINX, Inc.
 
서버 성능에 대한 정의와 이해
서버 성능에 대한 정의와 이해서버 성능에 대한 정의와 이해
서버 성능에 대한 정의와 이해중선 곽
 
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3Ji-Woong Choi
 
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushReal Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushLucas Jellema
 

What's hot (20)

Common issues with Apache Kafka® Producer
Common issues with Apache Kafka® ProducerCommon issues with Apache Kafka® Producer
Common issues with Apache Kafka® Producer
 
Introduction to Apache Camel
Introduction to Apache CamelIntroduction to Apache Camel
Introduction to Apache Camel
 
Nginx Essential
Nginx EssentialNginx Essential
Nginx Essential
 
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
왜 쿠버네티스는 systemd로 cgroup을 관리하려고 할까요
 
GraalVm and Quarkus
GraalVm and QuarkusGraalVm and Quarkus
GraalVm and Quarkus
 
Introduction to Python Asyncio
Introduction to Python AsyncioIntroduction to Python Asyncio
Introduction to Python Asyncio
 
이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정이벤트 기반 분산 시스템을 향한 여정
이벤트 기반 분산 시스템을 향한 여정
 
Terraform
TerraformTerraform
Terraform
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
Apache Flink and what it is used for
Apache Flink and what it is used forApache Flink and what it is used for
Apache Flink and what it is used for
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Learn nginx in 90mins
Learn nginx in 90minsLearn nginx in 90mins
Learn nginx in 90mins
 
NGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEANGINX ADC: Basics and Best Practices – EMEA
NGINX ADC: Basics and Best Practices – EMEA
 
Amazon EC2 Instance Types.pptx
Amazon EC2 Instance Types.pptxAmazon EC2 Instance Types.pptx
Amazon EC2 Instance Types.pptx
 
NGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEANGINX: Basics and Best Practices EMEA
NGINX: Basics and Best Practices EMEA
 
Introduction to Maven
Introduction to MavenIntroduction to Maven
Introduction to Maven
 
Spring Security
Spring SecuritySpring Security
Spring Security
 
서버 성능에 대한 정의와 이해
서버 성능에 대한 정의와 이해서버 성능에 대한 정의와 이해
서버 성능에 대한 정의와 이해
 
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
[오픈소스컨설팅] 아파치톰캣 운영가이드 v1.3
 
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server PushReal Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
Real Time UI with Apache Kafka Streaming Analytics of Fast Data and Server Push
 

Similar to Scalable Django Architecture

The State of WebSockets in Django
The State of WebSockets in DjangoThe State of WebSockets in Django
The State of WebSockets in DjangoRami Sayar
 
NYC Identity Summit Tech Day: ForgeRock DevOps/Cloud Strategy
NYC Identity Summit Tech Day: ForgeRock DevOps/Cloud StrategyNYC Identity Summit Tech Day: ForgeRock DevOps/Cloud Strategy
NYC Identity Summit Tech Day: ForgeRock DevOps/Cloud StrategyForgeRock
 
Architecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsArchitecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsRasheed Waraich
 
Containerdays Intro to Habitat
Containerdays Intro to HabitatContainerdays Intro to Habitat
Containerdays Intro to HabitatMandi Walls
 
Exploring pwa for shopware
Exploring pwa for shopwareExploring pwa for shopware
Exploring pwa for shopwareSander Mangel
 
Java EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The CloudJava EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The CloudBruno Borges
 
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...Edward Wilde
 
20 tips for website performance
20 tips for website performance20 tips for website performance
20 tips for website performanceAndrew Siemer
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQLKonstantin Gredeskoul
 
CQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersCQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersMarkus Eisele
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Markus Eisele
 
Preparing your dockerised application for production deployment
Preparing your dockerised application for production deploymentPreparing your dockerised application for production deployment
Preparing your dockerised application for production deploymentDave Ward
 
The Kitchen Cloud How To: Automating Joyent SmartMachines with Chef
The Kitchen Cloud How To: Automating Joyent SmartMachines with ChefThe Kitchen Cloud How To: Automating Joyent SmartMachines with Chef
The Kitchen Cloud How To: Automating Joyent SmartMachines with ChefChef Software, Inc.
 
Logs aggregation and analysis
Logs aggregation and analysisLogs aggregation and analysis
Logs aggregation and analysisDivante
 
How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015hirokiky
 
Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ TokopediaQasim Zaidi
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...In-Memory Computing Summit
 
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na NuvemTecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na NuvemBruno Borges
 

Similar to Scalable Django Architecture (20)

The State of WebSockets in Django
The State of WebSockets in DjangoThe State of WebSockets in Django
The State of WebSockets in Django
 
NYC Identity Summit Tech Day: ForgeRock DevOps/Cloud Strategy
NYC Identity Summit Tech Day: ForgeRock DevOps/Cloud StrategyNYC Identity Summit Tech Day: ForgeRock DevOps/Cloud Strategy
NYC Identity Summit Tech Day: ForgeRock DevOps/Cloud Strategy
 
Architecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web AppsArchitecture & Workflow of Modern Web Apps
Architecture & Workflow of Modern Web Apps
 
Containerdays Intro to Habitat
Containerdays Intro to HabitatContainerdays Intro to Habitat
Containerdays Intro to Habitat
 
Exploring pwa for shopware
Exploring pwa for shopwareExploring pwa for shopware
Exploring pwa for shopware
 
Java EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The CloudJava EE Arquillian Testing with Docker & The Cloud
Java EE Arquillian Testing with Docker & The Cloud
 
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
Docker and serverless Randstad Jan 2019: OpenFaaS Serverless: when functions ...
 
20 tips for website performance
20 tips for website performance20 tips for website performance
20 tips for website performance
 
12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL12-Step Program for Scaling Web Applications on PostgreSQL
12-Step Program for Scaling Web Applications on PostgreSQL
 
CQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java DevelopersCQRS and Event Sourcing for Java Developers
CQRS and Event Sourcing for Java Developers
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolith Stay productive while slicing up the monolith
Stay productive while slicing up the monolith
 
performance.ppt
performance.pptperformance.ppt
performance.ppt
 
Preparing your dockerised application for production deployment
Preparing your dockerised application for production deploymentPreparing your dockerised application for production deployment
Preparing your dockerised application for production deployment
 
The Kitchen Cloud How To: Automating Joyent SmartMachines with Chef
The Kitchen Cloud How To: Automating Joyent SmartMachines with ChefThe Kitchen Cloud How To: Automating Joyent SmartMachines with Chef
The Kitchen Cloud How To: Automating Joyent SmartMachines with Chef
 
Logs aggregation and analysis
Logs aggregation and analysisLogs aggregation and analysis
Logs aggregation and analysis
 
How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015How we realized SOA by Python at PyCon JP 2015
How we realized SOA by Python at PyCon JP 2015
 
Golang @ Tokopedia
Golang @ TokopediaGolang @ Tokopedia
Golang @ Tokopedia
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
 
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na NuvemTecnologias Oracle em Docker Containers On-premise e na Nuvem
Tecnologias Oracle em Docker Containers On-premise e na Nuvem
 

More from Rami Sayar

Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeRami Sayar
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesRami Sayar
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS DebuggingRami Sayar
 
An Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemAn Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemRami Sayar
 
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Rami Sayar
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressRami Sayar
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingRami Sayar
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
FITC - Bootstrap Unleashed
FITC - Bootstrap UnleashedFITC - Bootstrap Unleashed
FITC - Bootstrap UnleashedRami Sayar
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101Rami Sayar
 
FITC - Data Visualization in Practice
FITC - Data Visualization in PracticeFITC - Data Visualization in Practice
FITC - Data Visualization in PracticeRami Sayar
 

More from Rami Sayar (11)

Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
 
Web a Quebec - JS Debugging
Web a Quebec - JS DebuggingWeb a Quebec - JS Debugging
Web a Quebec - JS Debugging
 
An Intense Overview of the React Ecosystem
An Intense Overview of the React EcosystemAn Intense Overview of the React Ecosystem
An Intense Overview of the React Ecosystem
 
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
Creating Beautiful CSS3 Animations - FITC Amsterdam 2016
 
Here Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPressHere Be Dragons - Debugging WordPress
Here Be Dragons - Debugging WordPress
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
FITC - Bootstrap Unleashed
FITC - Bootstrap UnleashedFITC - Bootstrap Unleashed
FITC - Bootstrap Unleashed
 
FITC - Node.js 101
FITC - Node.js 101FITC - Node.js 101
FITC - Node.js 101
 
FITC - Data Visualization in Practice
FITC - Data Visualization in PracticeFITC - Data Visualization in Practice
FITC - Data Visualization in Practice
 

Recently uploaded

哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查ydyuyu
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsPriya Reddy
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdfMatthew Sinclair
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查ydyuyu
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制pxcywzqs
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Roommeghakumariji156
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...gajnagarg
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样ayvbos
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...kajalverma014
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfJOHNBEBONYAP1
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Balliameghakumariji156
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtrahman018755
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge GraphsEleniIlkou
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.krishnachandrapal52
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...kumargunjan9515
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样ayvbos
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdfMatthew Sinclair
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理F
 

Recently uploaded (20)

哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
哪里办理美国迈阿密大学毕业证(本硕)umiami在读证明存档可查
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf20240508 QFM014 Elixir Reading List April 2024.pdf
20240508 QFM014 Elixir Reading List April 2024.pdf
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac RoomVip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
Vip Firozabad Phone 8250092165 Escorts Service At 6k To 30k Along With Ac Room
 
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
Top profile Call Girls In Dindigul [ 7014168258 ] Call Me For Genuine Models ...
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
Real Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirtReal Men Wear Diapers T Shirts sweatshirt
Real Men Wear Diapers T Shirts sweatshirt
 
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.Meaning of On page SEO & its process in detail.
Meaning of On page SEO & its process in detail.
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...Local Call Girls in Seoni  9332606886 HOT & SEXY Models beautiful and charmin...
Local Call Girls in Seoni 9332606886 HOT & SEXY Models beautiful and charmin...
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
20240507 QFM013 Machine Intelligence Reading List April 2024.pdf
 
一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理一比一原版田纳西大学毕业证如何办理
一比一原版田纳西大学毕业证如何办理
 

Scalable Django Architecture

  • 1. Advanced Django Architecture Rami Sayar - @ramisayar Technical Evangelist Microsoft Canada
  • 2. Advanced Scalable Django Architecture Rami Sayar - @ramisayar Technical Evangelist Microsoft Canada
  • 3. Agenda •  Advanced Django Techniques & Patterns •  Structuring Complex Applications •  Scaling Django Applications •  Django Applications in Production CONFOO - @RAMISAYAR
  • 4. What is a production web app? •  Django is surrounded by tons of applications, services and code in production. •  Advanced Django architecture is needed to support Django in production without failing hard. CONFOO - @RAMISAYAR
  • 6. Load Balancing •  Load balancing Django improves the performance and reliability by distributing traffic. •  Becomes an interesting problem when you have to consider: •  SSL Termination •  Sticky Sessions? •  WebSockets? CONFOO - @RAMISAYAR
  • 7. Load Balancing = Django + HAProxy + SSL •  HAProxy gained native SSL support in HAProxy 1.5.x => June 2014! •  SSL Termination: •  Fairly straightforward to set up HAProxy. •  Read: How To Implement SSL Termination With HAProxy CONFOO - @RAMISAYAR
  • 8. Load Balancing Proxying & Remote Addr class SetRemoteAddrFromForwardedFor(object): def process_request(self, request): try: real_ip = request.META['HTTP_X_FORWARDED_FOR'] except KeyError: pass else: # HTTP_X_FORWARDED_FOR can be a comma-separated list of IPs. # Take just the first one. real_ip = real_ip.split(",")[0] request.META['REMOTE_ADDR'] = real_ip CONFOO - @RAMISAYAR
  • 9. Azure Traffic Manager •  High Performance Load Balancer + DNS Support. •  Sticky Sessions don’t exist. •  HTTPS Supported. CONFOO - @RAMISAYAR
  • 11. Caching = Django + Varnish •  Varnish has a tendency to just cache EVERYTHING which can be frustrating for the User, unless you set it up properly. •  Varnish does not cache content & cookies. •  Varnish and Django CSRF protection gotcha. •  Varnish does not deal with HTTPS (hence the need of HAProxy in front of Varnish). CONFOO - @RAMISAYAR
  • 12. Caching = Django + Varnish •  Django-Varnish – “It allows you to monitor certain models and when they are updated, Django Varnish will purge the model's absolute_url on your frontend(s). This ensures that object detail pages are served blazingly fast and are always up to date.” •  https://github.com/justquick/django-varnish •  Project Idea: Deeper Django/Varnish integration. CONFOO - @RAMISAYAR
  • 13. Caching = Django + Varnish •  https://www.varnish-cache.org/ •  http://www.isvarnishworking.com/ •  http://yml-blog.blogspot.ca/2010/01/esi-using-varnish-and- django.html •  http://chase-seibert.github.io/blog/2011/09/23/varnish-caching- for-unauthenticated-django-views.html •  http://blog.bigdinosaur.org/adventures-in-varnish/ •  http://www.nedproductions.biz/wiki/a-perfected-varnish-reverse- caching-proxy-vcl-script CONFOO - @RAMISAYAR
  • 15. Web Server = Django + Apache •  Forced to use Apache? Your options: •  mod_python (No) •  mod_wsgi (Yes) •  FastCGI (Deprecated since 1.7) •  Phusion Passenger (Yes) CONFOO - @RAMISAYAR
  • 16. Web Server = Django + Apache •  mod_wsgi •  Decent performance on the Apache side. •  You can setup Apache any way you like. •  You can setup mod_wsgi to use virtualenv. CONFOO - @RAMISAYAR
  • 17. Web Server = Django + Apache import os, sys, site # Add the site-packages of the chosen virtualenv to work with site.addsitedir('~/.virtualenvs/myprojectenv/local/lib/python2.7/site-packages') # Add the app's directory to the PYTHONPATH sys.path.append('/home/django_projects/MyProject') sys.path.append('/home/django_projects/MyProject/myproject') os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings' # Activate your virtual env activate_env=os.path.expanduser("~/.virtualenvs/myprojectenv/bin/activate_this.py") execfile(activate_env, dict(__file__=activate_env)) import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() CONFOO - @RAMISAYAR
  • 18. Web Server = Django + Alternatives (aka. Nginx) •  Nginx + uWSGI [uwsgi] touch-reload = /tmp/newproject socket = 127.0.0.1:3031 workers = 2 chdir = /srv/newproject env = DJANGO_SETTINGS_MODULE=newproject.settings module = django.core.handlers.wsgi:WSGIHander() CONFOO - @RAMISAYAR
  • 19. Web Server = Django + Alternatives (aka. Gunicorn) •  Nginx & Gunicorn •  In theory, you should use Nginx as a reverse proxy here, to serve static files if you’re not uploading everything to a CDN or a separate media server. If you are, you can use HAProxy and Gunicorn as a standalone webserver, one less dependency to care about. •  Install Gunicorn directly inside your virtual environment. •  Use Gaffer to monitor the Gunicorn. CONFOO - @RAMISAYAR
  • 20. Web Server - References •  http://blog.kgriffs.com/2012/12/18/uwsgi-vs-gunicorn-vs-node- benchmarks.html CONFOO - @RAMISAYAR
  • 21. REST APIs & Django CONFOO - @RAMISAYAR
  • 22. Use Django REST Framework! Django REST Framework vs Django Tasty Pie CONFOO - @RAMISAYAR
  • 23. Cache & Django CONFOO - @RAMISAYAR
  • 24. Caching in Production •  Caching – Django has multiple options: •  Redis. Make sure you use Hiredis and django-redis-cache. Use a hosted Redis Cache (Azure, AWS, etc). •  Memcached. Make sure you use pylibmc and not python-memcached, better performance with the C library. •  SSL still matters. CONFOO - @RAMISAYAR
  • 25. Azure Redis Cache CONFOO - @RAMISAYAR
  • 27. Logging in Production •  Logstash •  Collect logs, parse them, and store them for later use. •  Free and open source. •  Set it up with Redis. CONFOO - @RAMISAYAR
  • 28. Logging in Production – Use Python-Logstash LOGGING = { 'handlers': { 'logstash': { 'level': 'DEBUG', 'class': 'logstash.LogstashHandler', 'host': 'localhost', 'port': 5959, # Default value: 5959 'version': 1, # Version of logstash event schema. Default value: 0 (for backward compatibility of the library) 'message_type': 'logstash', # 'type' field in logstash message. Default value: 'logstash'. 'tags': ['tag1', 'tag2'], # list of tags. Default: None. }, }, CONFOO - @RAMISAYAR
  • 29. Logging in Production – Use Python-Logstash 'loggers': { 'django.request': { 'handlers': ['logstash'], 'level': 'DEBUG', 'propagate': True, }, }, } CONFOO - @RAMISAYAR
  • 30. Logging in Production – Using Sentry •  Realtime event logging and aggregation platform. •  Specialize in monitoring exceptions and errors. •  https://github.com/getsentry/sentry CONFOO - @RAMISAYAR
  • 32. PostgreSQL in Production – pgpool & slony •  PostgreSQL 9+ has streaming replication assuming you’re running identical databases with identical version on identical architectures (not really an issue). •  If not using the Streaming Replication feature (WAL), you’ll want to use either pgpool or slony to scale your PostgreSQL database across multiple machines. •  Use Slony if you want master-slave-peer replication. •  Use pgpool or pgbouncer for connection pooling. Pgbouncer only does connection pooling. CONFOO - @RAMISAYAR
  • 33. Async Tasks & Django CONFOO - @RAMISAYAR
  • 34. Async Tasks – Celery •  Use Celery for Asynchronous Tasks •  Use Celery with Redis and store results in Django ORM •  RQ is an alternative for distributing tasks. (Based on Redis) Read: http://www.caktusgroup.com/blog/2014/09/29/celery-production/ CONFOO - @RAMISAYAR
  • 35. On Redis •  Redis is extremely popular as an easy and simple publish- subscribe. •  Redis is very particular about memory. Running out of memory in Redis -> CRASH AND BURN! •  If you don’t have enough memory in your VM to run Redis Cache -> Change your approach, use Apache Kafka. CONFOO - @RAMISAYAR
  • 36. Tips & Techniques •  Don’t forget: •  Turn off Debug Mode •  Turn off Template Debug Mode •  Use different Django Settings Modules depending on the role and environment you are in through environment variables by setting “DJANGO_SETTINGS_MODULE”. CONFOO - @RAMISAYAR
  • 37. What did we learn? •  Scaling Django Architectures •  Most of the work surrounds Django •  Minimal changes to your django app for the most part. CONFOO - @RAMISAYAR
  • 38. Thank You! Questions? Follow @ramisayar CONFOO - @RAMISAYAR
  • 39. Resources •  http://blog.disqus.com/post/62187806135/scaling-django-to-8- billion-page-views •  http://engineering.hackerearth.com/2013/10/07/scaling- database-with-django-and-haproxy/ •  http://www.djangobook.com/en/2.0/chapter12.html •  https://www.digitalocean.com/community/tutorials/how-to- implement-ssl-termination-with-haproxy-on-ubuntu-14-04 •  https://docs.djangoproject.com/en/1.7/topics/security/ •  https://www.digitalocean.com/community/tutorials/how-to-scale- django-beyond-the-basics CONFOO - @RAMISAYAR
  • 40. ©2013  Microso-  Corpora1on.  All  rights  reserved.  Microso-,  Windows,  Office,  Azure,  System  Center,  Dynamics  and  other  product  names  are  or  may  be  registered  trademarks  and/or  trademarks  in  the   U.S.  and/or  other  countries.  The  informa1on  herein  is  for  informa1onal  purposes  only  and  represents  the  current  view  of  Microso-  Corpora1on  as  of  the  date  of  this  presenta1on.  Because  Microso-   must  respond  to  changing  market  condi1ons,  it  should  not  be  interpreted  to  be  a  commitment  on  the  part  of  Microso-,  and  Microso-  cannot  guarantee  the  accuracy  of  any  informa1on  provided  a-er   the  date  of  this  presenta1on.  MICROSOFT  MAKES  NO  WARRANTIES,  EXPRESS,  IMPLIED  OR  STATUTORY,  AS  TO  THE  INFORMATION  IN  THIS  PRESENTATION.  

Editor's Notes

  1. What does a web application look like in production?
  2. A few small complications, one of which is that every request’s remote IP (request.META["REMOTE_IP"]) will be that of the load balancer, not the actual IP making the request. Load balancers deal with this by setting a special header, X-Forwarded-For, to the actual requesting IP address. Use Middleware.
  3. A few small complications, one of which is that every request’s remote IP (request.META["REMOTE_IP"]) will be that of the load balancer, not the actual IP making the request. Load balancers deal with this by setting a special header, X-Forwarded-For, to the actual requesting IP address. Use Middleware.