SlideShare a Scribd company logo
So, You Want to Make a Production
          Django App
A Little Background
• Launching Production Django Apps since '06
  and 0.9something beta

• Launched and Managed Django Websites, E-
  Commerce Sites, and Web Apps for brands
  such as:

• Rip Curl, UT San Diego, Callaway Golf, DC
  Shoes, Dunlop, PacSun, and many many more
Goals
• Identify Common Pitfalls in Launching

• Point Out Django Gotchas

• Point Out Django Tools

• Help You Have a Smooth Launch

• Give Some Pointers on Managing and
  Maintaing a Django App
This Only Partially
  About Django
  and all about launching web apps
Going Production is...
• Putting it in front of consumers

• Promoting It

• Customer data

• 24/7/365

• Someone Else Is Using It

• Your billing relationship changes
But First, Some Quick
          Tips
Simple Django Things
• DEBUG = False

• Style your 500 / 404.html

• HTTPS Admin, login, and .. anywhere
  sensitive information is submitted

• Make your Sites record accurate
Simple Non-Django
          Things
• Favicon

• Run a Site Crawler

• Redirect to one domain - www

• Check your browser console for errors
So What Makes Your
   App Ready?
The Big Questions

• Is it Stable?

• Did I get it Right?

• Does it Perform?
Stability

• Stability is about predictable performance

• Thorough testing

• A way to track bugs and issues

• A way to monitor what's happening
Bug Tracking

• 500 Emails - Send these to a Gmail Account

• Sentry is cool

• Rotate your logs

• Stomp 500s, signal to noise is very important
Refactoring

• You probably didn't get all the data models
  and functionality right

• Following launch focus on fixing issues, not
  solving any misconceptions.
Ok, App Works Good,
Until the Newsletter Went
           Out
Performance part 1
• Memcached + ANONYMOUS_CACHE

• Django Debug Toolbar

• {% cache %}

• But, don't cache session specific stuff!

• Use Production Scale Data
Performance part 2
• We use Nginx + Gunicorn

• CDNs - use them, but use caution

• Expire Tags - speed without effort

• Premature Optimization is the root of all evil,
  but the night before launch is no longer
  premature, so save it in a temporary model on
  a signal damnit
Performance 2.1
• Our Setup

• Static Media from CDN

• Nginx or ELB or other load balancer

• Gunicorn managed by Supervisord

• MySQL or Postgresql

• Memcached, Elasticsearch, RabbitMQ
Performance part 3
• New Relic can tell you a lot

• Process long tasks with Celery

• Varnish can do wonders, if your app is doing the right thing

• But first optimize your queries and indexes

• Yes, you can do group bys and aggregates.. annotate and
  aggregate are not so intuitive

• DB Templates Are Expensive
Aggregate Digression



RateClass.objects.annotate(

      hours = Sum("person__timeentry__hours")).filter(

      person__timeentry__project__name="My Project')

)
But Enough About
       Performance

• Performance is usually something you see as
  you scale up and add complexity

• Your site should perform quickly, but even
  more importantly..
Things That Really
     Matter
Content!
• Is all the content the right content?

• No Lorem Ipsum

• Do all your forms submit? Are there human
  error messages.

• Is the contact information correct?
Browser Compatibility
• Did you check all your browsers?

• As a rule, CEOs use the oldest possible IE
  version

• There are over 100 million iPads, what does
  your site look like on one? CEOs usually have
  one of these too.
Security

• SSL logins! admins! everything!

• CSRF protection

• Are you assuming anything?
Search Matters
• robots.txt

• canonical tags

• meta tags

• analytics tags

• duplicate content
What Used to Be
 Searched Also Matters


• Pages with rankings are valuable

• If it was a link on Google, don't make it a 404
Things You Should
Have Already Done
Training
• Not everyone groks abstractions, explain
  how to do things

• Make sure your client knows that access to
  Users == Super User

• Take a moment to polish your Change List
  and Change Form Templates
Dev Site
• Have one

• Make sure it doesn't send email to anyone

• Make sure it says "DEV SITE" somewhere on the front end

• Make sure it has robots.txt disallowing all

• If possible, control access

• Keep track of any integration credentials for sandbox vs
  production
Configuration
         Management

• Settings Can Get Unruly

• We use cascading imports to structure them

• Beware Stored Passwords!
Testing
• Unit Tests are nice, if you have been doing
  them all along

• Test it by hand

• Test it like a consumer

• - Bad / Missing Data

• - International Data / Unicode
Migrations

• Use South, or don't but be prepared to tear
  your hair out either way

• Is there existing data to import? Do a dry run
  - build this into management commands
Ok We Are Ready!
Launch is in 1 week
• Lower your DNS TTL

• Make sure you have access to all the domain information

• Are all integrations ready for production? With production credentials?

• A Dry Run is worth the effort

• Do you know all the DNS records you are changing? Are the
  nameservers in your control?

• Test your site with /etc/hosts, make sure it is ready to go

• Write up a plan, and let everyone know the timing
Launch!
• Sometimes, it is better to just get it done.

• But not always

• But sometimes, really, it just has to fly

• Walk through everything

• Run transactions on your credit card, and then cancel
  them

• Doubt everything
Deployment

• Revision your deploys with Git

• Automate it as much as possible

• But don't put off automating most of it

• Read the 11-Factor App
DNS Gotchas
• Nameservers! Don't change unless you know
  all the records that are there

• SPF, PTR - make sure your email makes it
  through the spam filter

• IT departments don't get CNAMEs, so watch
  your load balancers!
Woo Hoo! It's Up!
  Now What
     Are We Done?
Post Launch

• Keep track of what you agreed to build.

• Good fences make good neighbors

• When You Launch, You are in Maintenance
  Mode. Make the Mental Shift!
Refactors, Again
• Actually that did need to be a separate
  model

• See, South was a good idea

• Ouch you should have used South

• Either way, you need to write a manage
  command
Maintenance Tips and
        Tricks

• Manage commands are really useful

• So is the shell

• Know what you plan to do on a server before
  logging in
The Long View

• Don't focus on the bad things, focus on what
  was achieved

• What simple things can you do to make the
  next one smoother

• Checklists!
Questions?

More Related Content

KEY
Erlang - Dive Right In
PPTX
Code Yellow: Helping Operations Top-Heavy Teams the Smart Way
PDF
Get Off My Thread! - keep your UI super-responsive
PPTX
Why Does (My) Monitoring Suck?
PPTX
Automate Everything! (No stress development/Tallinn)
PDF
Devops, Secops, Opsec, DevSec *ops *.* ?
PPT
Continuous integration meetup
PDF
8 Simple Rules for Consuming APIs
Erlang - Dive Right In
Code Yellow: Helping Operations Top-Heavy Teams the Smart Way
Get Off My Thread! - keep your UI super-responsive
Why Does (My) Monitoring Suck?
Automate Everything! (No stress development/Tallinn)
Devops, Secops, Opsec, DevSec *ops *.* ?
Continuous integration meetup
8 Simple Rules for Consuming APIs

What's hot (20)

PPTX
Continuous database deployment
PPTX
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
PDF
Speed up your Serverless development flow
PPTX
Minimum Viable Architecture - Good Enough is Good Enough
PPTX
Webhooks with Azure Functions - Live 360 Conference
PDF
A Business Case for Git - Tim Pettersen
PPTX
14 Habits of Great SQL Developers
PPTX
Moving Fast At Scale
PPTX
Evolving Architecture and Organization - Lessons from Google and eBay
PPTX
Minimum Viable Architecture -- Good Enough is Good Enough in a Startup
PDF
Optimizing Git LFS Migration Through Repository Data-mining
PPT
Gdco12 kartik ayyar
PDF
An introduction to Reactive applications, Reactive Streams, and options for t...
PPTX
Scaling Your Architecture for the Long Term
PPTX
One Terrible Day at Google, and How It Made Us Better
PDF
Distributed Release Management
PDF
Quality at Speed - Penny Wyatt
PDF
Get lean tutorial
PDF
Supervise your Akka actors - Devoxx
PPTX
DevOps - It's About How We Work
Continuous database deployment
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
Speed up your Serverless development flow
Minimum Viable Architecture - Good Enough is Good Enough
Webhooks with Azure Functions - Live 360 Conference
A Business Case for Git - Tim Pettersen
14 Habits of Great SQL Developers
Moving Fast At Scale
Evolving Architecture and Organization - Lessons from Google and eBay
Minimum Viable Architecture -- Good Enough is Good Enough in a Startup
Optimizing Git LFS Migration Through Repository Data-mining
Gdco12 kartik ayyar
An introduction to Reactive applications, Reactive Streams, and options for t...
Scaling Your Architecture for the Long Term
One Terrible Day at Google, and How It Made Us Better
Distributed Release Management
Quality at Speed - Penny Wyatt
Get lean tutorial
Supervise your Akka actors - Devoxx
DevOps - It's About How We Work
Ad

Viewers also liked (12)

PDF
Django at Scale
PDF
Scaling Django Dc09
PDF
Django admin
PDF
Advanced Django
KEY
Advanced Django ORM techniques
PDF
Customizing the Django Admin
PDF
Django in the Real World
PDF
Scalable Django Architecture
PDF
High Availability Django - Djangocon 2016
PPTX
Django rest framework
PDF
Django Best Practices
KEY
Scaling Django
Django at Scale
Scaling Django Dc09
Django admin
Advanced Django
Advanced Django ORM techniques
Customizing the Django Admin
Django in the Real World
Scalable Django Architecture
High Availability Django - Djangocon 2016
Django rest framework
Django Best Practices
Scaling Django
Ad

Similar to Django production (20)

PDF
Class 7: Introduction to web technology entrepreneurship
PPT
Cloud Hosting for Government Agencies: Drupal Platform as a Service
PDF
Scalable, good, cheap
PPT
Planning for-high-performance-web-application
KEY
Dibi Conference 2012
PDF
Have you cleared the cache?
PPTX
Infrastructure Considerations : Design : "webops"
PPTX
Techzim Surge: Important Considerations for Hosting Web or Mobile Apps
PDF
Rails Hosting and the Woes
PDF
A Perfect Launch, Every Time
PPT
Continuous Deployment
PDF
Clearly, I Have Made Some Bad Decisions
PDF
Rails Operations - Lessons Learned
PPTX
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
PDF
Pownce Lessons Learned
KEY
improving the performance of Rails web Applications
PPTX
Best Practices for WordPress in Enterprise
PPT
Planning For High Performance Web Application
PPTX
The 6k startup - How to Launch a Startup on a Budget
KEY
Windycityrails page performance
Class 7: Introduction to web technology entrepreneurship
Cloud Hosting for Government Agencies: Drupal Platform as a Service
Scalable, good, cheap
Planning for-high-performance-web-application
Dibi Conference 2012
Have you cleared the cache?
Infrastructure Considerations : Design : "webops"
Techzim Surge: Important Considerations for Hosting Web or Mobile Apps
Rails Hosting and the Woes
A Perfect Launch, Every Time
Continuous Deployment
Clearly, I Have Made Some Bad Decisions
Rails Operations - Lessons Learned
Get Django, Get Hired - An opinionated guide to getting the best job, for the...
Pownce Lessons Learned
improving the performance of Rails web Applications
Best Practices for WordPress in Enterprise
Planning For High Performance Web Application
The 6k startup - How to Launch a Startup on a Budget
Windycityrails page performance

More from pythonsd (8)

PDF
Pep 465 - Matrix Multiplication in Python
PDF
Sqlalchemy lightning talk
PDF
PythonSD Test Driven Django Development Workshop
PDF
Matplotlib demo code
PDF
Matplotlib presentation 20 apr2013 final
PDF
Blaze the-evolution-of-numpy
PDF
Django Toolbox
PDF
Why Python 3
Pep 465 - Matrix Multiplication in Python
Sqlalchemy lightning talk
PythonSD Test Driven Django Development Workshop
Matplotlib demo code
Matplotlib presentation 20 apr2013 final
Blaze the-evolution-of-numpy
Django Toolbox
Why Python 3

Django production

  • 1. So, You Want to Make a Production Django App
  • 2. A Little Background • Launching Production Django Apps since '06 and 0.9something beta • Launched and Managed Django Websites, E- Commerce Sites, and Web Apps for brands such as: • Rip Curl, UT San Diego, Callaway Golf, DC Shoes, Dunlop, PacSun, and many many more
  • 3. Goals • Identify Common Pitfalls in Launching • Point Out Django Gotchas • Point Out Django Tools • Help You Have a Smooth Launch • Give Some Pointers on Managing and Maintaing a Django App
  • 4. This Only Partially About Django and all about launching web apps
  • 5. Going Production is... • Putting it in front of consumers • Promoting It • Customer data • 24/7/365 • Someone Else Is Using It • Your billing relationship changes
  • 6. But First, Some Quick Tips
  • 7. Simple Django Things • DEBUG = False • Style your 500 / 404.html • HTTPS Admin, login, and .. anywhere sensitive information is submitted • Make your Sites record accurate
  • 8. Simple Non-Django Things • Favicon • Run a Site Crawler • Redirect to one domain - www • Check your browser console for errors
  • 9. So What Makes Your App Ready?
  • 10. The Big Questions • Is it Stable? • Did I get it Right? • Does it Perform?
  • 11. Stability • Stability is about predictable performance • Thorough testing • A way to track bugs and issues • A way to monitor what's happening
  • 12. Bug Tracking • 500 Emails - Send these to a Gmail Account • Sentry is cool • Rotate your logs • Stomp 500s, signal to noise is very important
  • 13. Refactoring • You probably didn't get all the data models and functionality right • Following launch focus on fixing issues, not solving any misconceptions.
  • 14. Ok, App Works Good, Until the Newsletter Went Out
  • 15. Performance part 1 • Memcached + ANONYMOUS_CACHE • Django Debug Toolbar • {% cache %} • But, don't cache session specific stuff! • Use Production Scale Data
  • 16. Performance part 2 • We use Nginx + Gunicorn • CDNs - use them, but use caution • Expire Tags - speed without effort • Premature Optimization is the root of all evil, but the night before launch is no longer premature, so save it in a temporary model on a signal damnit
  • 17. Performance 2.1 • Our Setup • Static Media from CDN • Nginx or ELB or other load balancer • Gunicorn managed by Supervisord • MySQL or Postgresql • Memcached, Elasticsearch, RabbitMQ
  • 18. Performance part 3 • New Relic can tell you a lot • Process long tasks with Celery • Varnish can do wonders, if your app is doing the right thing • But first optimize your queries and indexes • Yes, you can do group bys and aggregates.. annotate and aggregate are not so intuitive • DB Templates Are Expensive
  • 19. Aggregate Digression RateClass.objects.annotate( hours = Sum("person__timeentry__hours")).filter( person__timeentry__project__name="My Project') )
  • 20. But Enough About Performance • Performance is usually something you see as you scale up and add complexity • Your site should perform quickly, but even more importantly..
  • 22. Content! • Is all the content the right content? • No Lorem Ipsum • Do all your forms submit? Are there human error messages. • Is the contact information correct?
  • 23. Browser Compatibility • Did you check all your browsers? • As a rule, CEOs use the oldest possible IE version • There are over 100 million iPads, what does your site look like on one? CEOs usually have one of these too.
  • 24. Security • SSL logins! admins! everything! • CSRF protection • Are you assuming anything?
  • 25. Search Matters • robots.txt • canonical tags • meta tags • analytics tags • duplicate content
  • 26. What Used to Be Searched Also Matters • Pages with rankings are valuable • If it was a link on Google, don't make it a 404
  • 27. Things You Should Have Already Done
  • 28. Training • Not everyone groks abstractions, explain how to do things • Make sure your client knows that access to Users == Super User • Take a moment to polish your Change List and Change Form Templates
  • 29. Dev Site • Have one • Make sure it doesn't send email to anyone • Make sure it says "DEV SITE" somewhere on the front end • Make sure it has robots.txt disallowing all • If possible, control access • Keep track of any integration credentials for sandbox vs production
  • 30. Configuration Management • Settings Can Get Unruly • We use cascading imports to structure them • Beware Stored Passwords!
  • 31. Testing • Unit Tests are nice, if you have been doing them all along • Test it by hand • Test it like a consumer • - Bad / Missing Data • - International Data / Unicode
  • 32. Migrations • Use South, or don't but be prepared to tear your hair out either way • Is there existing data to import? Do a dry run - build this into management commands
  • 33. Ok We Are Ready!
  • 34. Launch is in 1 week • Lower your DNS TTL • Make sure you have access to all the domain information • Are all integrations ready for production? With production credentials? • A Dry Run is worth the effort • Do you know all the DNS records you are changing? Are the nameservers in your control? • Test your site with /etc/hosts, make sure it is ready to go • Write up a plan, and let everyone know the timing
  • 35. Launch! • Sometimes, it is better to just get it done. • But not always • But sometimes, really, it just has to fly • Walk through everything • Run transactions on your credit card, and then cancel them • Doubt everything
  • 36. Deployment • Revision your deploys with Git • Automate it as much as possible • But don't put off automating most of it • Read the 11-Factor App
  • 37. DNS Gotchas • Nameservers! Don't change unless you know all the records that are there • SPF, PTR - make sure your email makes it through the spam filter • IT departments don't get CNAMEs, so watch your load balancers!
  • 38. Woo Hoo! It's Up! Now What Are We Done?
  • 39. Post Launch • Keep track of what you agreed to build. • Good fences make good neighbors • When You Launch, You are in Maintenance Mode. Make the Mental Shift!
  • 40. Refactors, Again • Actually that did need to be a separate model • See, South was a good idea • Ouch you should have used South • Either way, you need to write a manage command
  • 41. Maintenance Tips and Tricks • Manage commands are really useful • So is the shell • Know what you plan to do on a server before logging in
  • 42. The Long View • Don't focus on the bad things, focus on what was achieved • What simple things can you do to make the next one smoother • Checklists!