SlideShare a Scribd company logo
1 of 13
Coding For
“Production”
 a bit.ly tech talk 9/29/10
           @jehiah
• Who am I writing code for?
• What is a sandbox?
• Do you use internal APIs?
• Are exceptions cool?
• Who handles logging?
• How do you design for scale?
Who am I writing code for?
               A: Everyone Else!

  • anyone should be able to jump in and run/
    change/fix any piece of your architecture
  • make startup easy (even if your app is
    useless without data, run without it)
  • write simple code (don’t use fancy or
    advanced programing features)
Who am I writing code for?
  • script everything you do; it helps others
    learn how to use/manage your code.
  • use system wide resources to make
    bootstrapping your code the same as
    everything else. Avoid making your app
    “special”
  • don't re-invent start/stop scripts, run paths,
    logging, monitoring, data collection,
    deployment, upgrades
Sandbox
• You should always have a sandbox
  environment where your application ONLY
  talks to other sandbox’d applications
• Your application should never know which
  of the two it’s in (only your settings file
  should know this)
• Sandboxes let you break things, throw away
  data, and start over with no penalty or risk.
Test New
Data Code

            New Code

Sandbox       Data     Production

              Data
How do you keep your code from knowing
            where it is running?




fetch('http://backend.server.com/api?' +
urllib.urlencode(...))
fetch(settings.get('metrics_backend’) + '/api?' +
urllib.urlencode(...))
http://gist.github.com/595574

import tornado.options
tornado.options.define("environment", default="dev", help="environment")


options = {
    "dev" : {
        "metrics_api" : "http://127.0.0.1:8080",
    },
    "prod" : {
        "metrics_api" : "http://remote-server1.com",
    }
}

# settings that are the same for each environment
# (ie: they are here just to make them easy to find/change/update)
default_options = {
    "num_results" : 15,
}

def get(key):
    env = tornado.options.options.environment
    if env not in options:
        raise Exception("Invalid Environment (%s)" % env)
    v = options.get(env).get(key) or default_options.get(key)
    return v
Exceptions are for
      Developers
• exceptions help you find what to do next.
• fail hard and fail fast.
• assert your expectations
• when you find a problem with your code,
  always ask what error would have helped
  me find this sooner, and then add that
  error
Exceptions are for
               Developers

•   if you accidentally pass a string instead of an integer, add
    > assert isinstance(var, int)
•   scripts that take files as args should test that they exist
    > assert os.path.exists(filename)
•   don't catch exceptions. they are good! if you do catch
    an exception logging.exception() so it doesn't get lost.
Be Lazy
Expect something else to handle:
 • Logging (and log collection/rotation)
 • Running Monitoring Checks (and alerting)
 • start/stop scripts
 • deploy scripts
 • installing dependency libraries
 • state
Logging
• application logging is for errors and
  contexts not for auditing
• don’t get confused: sometimes we call raw
  data “logs”. For example: access logs. these
  are raw data files not logs.
• use logging module for timestamps, stack
  traces (context). don’t use print.
Designing for scale:
•   Assume 100x of your app/script might be
    running simultaneously
•   Always single thread
•   Use stateless connections (they give you
    hooks to scale) http->nginx->load balancer
•   Client knows what the data is, the remote
    end treats it like a blob or key/value store
•   Be as generic as possible and as specific as
    possible, never in between.

More Related Content

What's hot (6)

libAttachSQL, The Next-Generation C Connector For MySQL
libAttachSQL, The Next-Generation C Connector For MySQLlibAttachSQL, The Next-Generation C Connector For MySQL
libAttachSQL, The Next-Generation C Connector For MySQL
 
AppSec USA 2015: Customizing Burp Suite
AppSec USA 2015: Customizing Burp SuiteAppSec USA 2015: Customizing Burp Suite
AppSec USA 2015: Customizing Burp Suite
 
Owasp tds
Owasp tdsOwasp tds
Owasp tds
 
Python and web driver
Python and web driverPython and web driver
Python and web driver
 
Ruxmon cve 2012-2661
Ruxmon cve 2012-2661Ruxmon cve 2012-2661
Ruxmon cve 2012-2661
 
Entomology 101
Entomology 101Entomology 101
Entomology 101
 

Viewers also liked (7)

Data Processing @ bit.ly - Posscon 2011
Data Processing @ bit.ly - Posscon 2011Data Processing @ bit.ly - Posscon 2011
Data Processing @ bit.ly - Posscon 2011
 
Educational measurement, assessment and evaluation
Educational measurement, assessment and evaluationEducational measurement, assessment and evaluation
Educational measurement, assessment and evaluation
 
Introduction to .NET Framework and C# (English)
Introduction to .NET Framework and C# (English)Introduction to .NET Framework and C# (English)
Introduction to .NET Framework and C# (English)
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSS
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and Adolescents
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back Kid
 

Similar to Coding for production

CodeIgniter Ant Scripting
CodeIgniter Ant ScriptingCodeIgniter Ant Scripting
CodeIgniter Ant Scripting
Albert Rosa
 
Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5
Jim Manico
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
Clay Helberg
 

Similar to Coding for production (20)

introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
PyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web ApplicationsPyCon AU 2012 - Debugging Live Python Web Applications
PyCon AU 2012 - Debugging Live Python Web Applications
 
OWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA TestersOWASP ZAP Workshop for QA Testers
OWASP ZAP Workshop for QA Testers
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
DCRUG: Achieving Development-Production Parity
DCRUG: Achieving Development-Production ParityDCRUG: Achieving Development-Production Parity
DCRUG: Achieving Development-Production Parity
 
Rails Security
Rails SecurityRails Security
Rails Security
 
Habitat Overview
Habitat OverviewHabitat Overview
Habitat Overview
 
Debugging webOS applications
Debugging webOS applicationsDebugging webOS applications
Debugging webOS applications
 
Time Series Anomaly Detection with Azure and .NETT
Time Series Anomaly Detection with Azure and .NETTTime Series Anomaly Detection with Azure and .NETT
Time Series Anomaly Detection with Azure and .NETT
 
CodeIgniter Ant Scripting
CodeIgniter Ant ScriptingCodeIgniter Ant Scripting
CodeIgniter Ant Scripting
 
Splunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shellsSplunk: Forward me the REST of those shells
Splunk: Forward me the REST of those shells
 
Consolidating MLOps at One of Europe’s Biggest Airports
Consolidating MLOps at One of Europe’s Biggest AirportsConsolidating MLOps at One of Europe’s Biggest Airports
Consolidating MLOps at One of Europe’s Biggest Airports
 
Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5Top Ten Proactive Web Security Controls v5
Top Ten Proactive Web Security Controls v5
 
Don't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen EmeryDon't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen Emery
 
Don't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen EmeryDon't Mind the Gap by Galen Emery
Don't Mind the Gap by Galen Emery
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis technique
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Blue Teaming on a Budget of Zero
Blue Teaming on a Budget of ZeroBlue Teaming on a Budget of Zero
Blue Teaming on a Budget of Zero
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
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
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

Coding for production

  • 1. Coding For “Production” a bit.ly tech talk 9/29/10 @jehiah
  • 2. • Who am I writing code for? • What is a sandbox? • Do you use internal APIs? • Are exceptions cool? • Who handles logging? • How do you design for scale?
  • 3. Who am I writing code for? A: Everyone Else! • anyone should be able to jump in and run/ change/fix any piece of your architecture • make startup easy (even if your app is useless without data, run without it) • write simple code (don’t use fancy or advanced programing features)
  • 4. Who am I writing code for? • script everything you do; it helps others learn how to use/manage your code. • use system wide resources to make bootstrapping your code the same as everything else. Avoid making your app “special” • don't re-invent start/stop scripts, run paths, logging, monitoring, data collection, deployment, upgrades
  • 5. Sandbox • You should always have a sandbox environment where your application ONLY talks to other sandbox’d applications • Your application should never know which of the two it’s in (only your settings file should know this) • Sandboxes let you break things, throw away data, and start over with no penalty or risk.
  • 6. Test New Data Code New Code Sandbox Data Production Data
  • 7. How do you keep your code from knowing where it is running? fetch('http://backend.server.com/api?' + urllib.urlencode(...)) fetch(settings.get('metrics_backend’) + '/api?' + urllib.urlencode(...))
  • 8. http://gist.github.com/595574 import tornado.options tornado.options.define("environment", default="dev", help="environment") options = {     "dev" : {         "metrics_api" : "http://127.0.0.1:8080",     },     "prod" : {         "metrics_api" : "http://remote-server1.com",     } } # settings that are the same for each environment # (ie: they are here just to make them easy to find/change/update) default_options = {     "num_results" : 15, } def get(key):     env = tornado.options.options.environment     if env not in options:         raise Exception("Invalid Environment (%s)" % env)     v = options.get(env).get(key) or default_options.get(key)     return v
  • 9. Exceptions are for Developers • exceptions help you find what to do next. • fail hard and fail fast. • assert your expectations • when you find a problem with your code, always ask what error would have helped me find this sooner, and then add that error
  • 10. Exceptions are for Developers • if you accidentally pass a string instead of an integer, add > assert isinstance(var, int) • scripts that take files as args should test that they exist > assert os.path.exists(filename) • don't catch exceptions. they are good! if you do catch an exception logging.exception() so it doesn't get lost.
  • 11. Be Lazy Expect something else to handle: • Logging (and log collection/rotation) • Running Monitoring Checks (and alerting) • start/stop scripts • deploy scripts • installing dependency libraries • state
  • 12. Logging • application logging is for errors and contexts not for auditing • don’t get confused: sometimes we call raw data “logs”. For example: access logs. these are raw data files not logs. • use logging module for timestamps, stack traces (context). don’t use print.
  • 13. Designing for scale: • Assume 100x of your app/script might be running simultaneously • Always single thread • Use stateless connections (they give you hooks to scale) http->nginx->load balancer • Client knows what the data is, the remote end treats it like a blob or key/value store • Be as generic as possible and as specific as possible, never in between.