Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django Apps to Services

Django Apps to Services

Craig Kerstiens

July 18, 2012
Tweet

More Decks by Craig Kerstiens

Other Decks in Programming

Transcript

  1. Django Apps to Services

    View Slide

  2. Craig Kerstiens
    @craigkerstiens work at @heroku

    View Slide

  3. Project A collection of configuration and apps for a particular Website.
    (per Django Project)
    Django

    View Slide

  4. Project
    App
    A collection of configuration and apps for a particular Website.
    (per Django Project)
    Django

    View Slide

  5. Project
    App
    A collection of configuration and apps for a particular Website.
    A web application that does something. I.e. Weblog, Poll, Ticket
    system
    (per Django Project)
    Django

    View Slide

  6. Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table

    View Slide

  7. Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table

    View Slide

  8. Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    Table
    App

    View Slide

  9. Within Django

    View Slide

  10. Project
    Within Django

    View Slide

  11. Project
    App
    App
    App
    Within Django

    View Slide

  12. Project
    App
    App
    App
    Tickets
    FAQ
    FaqCreator
    Within Django

    View Slide

  13. Project
    App
    App
    App
    Tickets
    FAQ
    FaqCreator
    Within Django
    cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    ./faq/admin.py
    ./faq/forms.py
    ./faq/models.py
    ./faq/urls.py
    ./faq/views.py
    ./faqcreator/admin.py
    ./faqcreator/forms.py
    ./faqcreator/models.py
    ./faqcreator/urls.py
    ./faqcreator/views.py
    ./tickets/admin.py
    ./tickets/forms.py
    ./tickets/models.py
    ./tickets/urls.py
    ./tickets/views.py

    View Slide

  14. Reusability

    View Slide

  15. cd myproject && find .
    Reusability

    View Slide

  16. cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    ./faq/admin.py
    ./faq/forms.py
    ./faq/models.py
    ./faq/urls.py
    ./faq/views.py
    ./faqcreator/admin.py
    ./faqcreator/forms.py
    ./faqcreator/models.py
    ./faqcreator/urls.py
    ./faqcreator/views.py
    ./tickets/admin.py
    ./tickets/forms.py
    ./tickets/models.py
    ./tickets/urls.py
    ./tickets/views.py
    Reusability

    View Slide

  17. cd myproject && find .
    cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    ./faq/admin.py
    ./faq/forms.py
    ./faq/models.py
    ./faq/urls.py
    ./faq/views.py
    ./faqcreator/admin.py
    ./faqcreator/forms.py
    ./faqcreator/models.py
    ./faqcreator/urls.py
    ./faqcreator/views.py
    ./tickets/admin.py
    ./tickets/forms.py
    ./tickets/models.py
    ./tickets/urls.py
    ./tickets/views.py
    -->
    Reusability

    View Slide

  18. cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    ./faq/admin.py
    ./faq/forms.py
    ./faq/models.py
    ./faq/urls.py
    ./faq/views.py
    ./faqcreator/admin.py
    ./faqcreator/forms.py
    ./faqcreator/models.py
    ./faqcreator/urls.py
    ./faqcreator/views.py
    ./tickets/admin.py
    ./tickets/forms.py
    ./tickets/models.py
    ./tickets/urls.py
    ./tickets/views.py
    -->
    Reusability

    View Slide

  19. cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    cat myproject/requirements.txt
    cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    ./faq/admin.py
    ./faq/forms.py
    ./faq/models.py
    ./faq/urls.py
    ./faq/views.py
    ./faqcreator/admin.py
    ./faqcreator/forms.py
    ./faqcreator/models.py
    ./faqcreator/urls.py
    ./faqcreator/views.py
    ./tickets/admin.py
    ./tickets/forms.py
    ./tickets/models.py
    ./tickets/urls.py
    ./tickets/views.py
    -->
    Reusability

    View Slide

  20. cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    cat myproject/requirements.txt
    faq==0.1
    faqcreator==0.1
    tickets==0.1
    cd myproject && find .
    manage.py
    requirements.txt
    settings.py
    urls.py
    ./faq/admin.py
    ./faq/forms.py
    ./faq/models.py
    ./faq/urls.py
    ./faq/views.py
    ./faqcreator/admin.py
    ./faqcreator/forms.py
    ./faqcreator/models.py
    ./faqcreator/urls.py
    ./faqcreator/views.py
    ./tickets/admin.py
    ./tickets/forms.py
    ./tickets/models.py
    ./tickets/urls.py
    ./tickets/views.py
    -->
    Reusability

    View Slide

  21. View Slide

  22. REUSABILITY means faster features due to DRY
    (Don’t Repeat Yourself)

    View Slide

  23. REUSABILITY means faster features due to DRY
    (Don’t Repeat Yourself)
    REUSABILITY does not always mean SCALABILITY
    or MAINTAINABILITY

    View Slide

  24. REUSABILITY means faster features due to DRY
    (Don’t Repeat Yourself)
    REUSABILITY does not always mean SCALABILITY
    or MAINTAINABILITY

    View Slide

  25. Project
    App
    A collection of configuration and apps for a particular Website.
    A web application that does something. I.e. Weblog, Poll, Ticket
    system
    (per Django Project)
    Django

    View Slide

  26. Project
    App
    A collection of configuration and apps for a particular Website.
    A web application that does something. I.e. Weblog, Poll, Ticket
    system
    (per Django Project)
    Django

    View Slide

  27. Project
    App
    A collection of configuration and apps for a particular Website.
    A web application that does something. I.e. Weblog, Poll, Ticket
    system
    Django
    Service Method of communication over the web.
    Web APIs allow combination of multiple services

    View Slide

  28. View Slide

  29. Tech imitate Teams
    Project
    App
    App
    App
    Tickets
    FAQ
    FaqCreator
    Company
    Support
    Knowledge Base

    View Slide

  30. Support
    Knowledge Base
    Teams

    View Slide

  31. App
    App
    Support
    Knowledge Base
    Teams Grow

    View Slide

  32. App
    App
    Support
    Knowledge Base
    Billing
    Teams Grow

    View Slide

  33. App
    App
    Support
    Knowledge Base
    Billing
    Marketing
    Teams Grow

    View Slide

  34. App
    App
    Support
    Knowledge Base
    Billing
    Marketing
    Analytics
    Mobile
    API
    Front End
    Social
    Teams Grow

    View Slide

  35. App
    App
    App
    Support
    Knowledge Base
    Billing
    Apps Grow
    Marketing
    Analytics
    Mobile
    API
    Front End
    Social
    3 Apps

    View Slide

  36. App
    App
    App
    Support
    Knowledge Base
    Billing
    Apps Grow
    App
    App
    App
    Marketing
    Analytics
    Mobile
    App
    App
    App
    API
    Front End
    Social
    9 Apps

    View Slide

  37. Support
    Knowledge Base
    Billing
    Apps Grow
    Marketing
    Analytics
    Mobile
    API
    Front End
    Social
    9 Apps
    1 Codebase

    View Slide

  38. SOA To the Rescue

    View Slide

  39. SOA To the Rescue

    View Slide

  40. SOA To the Rescue

    View Slide

  41. Defined contract for communicating
    Service

    View Slide

  42. Defined contract for communicating
    Service
    $ curl -O $FAQ_API/create/ -X “question=my\ question source=123”

    View Slide

  43. In Python

    View Slide

  44. In Python
    data = {
    ‘question’: “my question”,
    ‘source’: 123
    }
    requests.POST(os.environ[‘FAQ_API’] + ‘/create/’, data=data)

    View Slide

  45. Version Bump
    data = {
    ‘question’: “my question”,
    ‘source’: 123,
    ‘related’: [456, 789]
    }
    requests.POST(os.environ[‘FAQ_API’] + ‘/v2/create’, data=data)

    View Slide

  46. Version Bump
    data = {
    ‘question’: “my question”,
    ‘source’: 123,
    ‘related’: [456, 789]
    }
    requests.POST(os.environ[‘FAQ_API’] + ‘/v2/create’, data=data)

    View Slide

  47. Version Bump
    data = {
    ‘question’: “my question”,
    ‘source’: 123,
    ‘related’: [456, 789]
    }
    requests.POST(os.environ[‘FAQ_API’] + ‘/v2/create’, data=data)
    STILL VALID
    requests.POST(os.environ[‘FAQ_API’] + ‘/v1/create’, data=data)

    View Slide

  48. What’s a service
    Provider API_HOST= http://127.0.0.1

    View Slide

  49. What’s a service
    Provider
    Endpoint
    API_HOST= http://127.0.0.1
    /v1/create/

    View Slide

  50. What’s a service
    Provider
    Endpoint
    API_HOST= http://127.0.0.1
    /v1/create/
    Contract {
    ‘question’: ‘foo bar’,
    ‘source’: 123
    }

    View Slide

  51. Service
    App

    View Slide

  52. Service
    App
    Models
    Views
    URLs
    Provider Endpoint Contract

    View Slide

  53. A SERVICE means REUSABILITY
    and enables SCALABILITY and
    MAINTAINABILITY

    View Slide

  54. A SERVICE means REUSABILITY
    and enables SCALABILITY and
    MAINTAINABILITY

    View Slide

  55. In the real world

    View Slide

  56. In the real world

    View Slide

  57. In the real world
    Install Sentry

    View Slide

  58. In the real world
    Install Sentry
    Send lots of data

    View Slide

  59. In the real world
    Install Sentry
    Send lots of data
    ...........

    View Slide

  60. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry

    View Slide

  61. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........

    View Slide

  62. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........
    Scale sentry

    View Slide

  63. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........
    Scale sentry
    ...........

    View Slide

  64. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........
    Scale sentry
    ...........
    Some time later, scale the app
    you build

    View Slide

  65. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........
    Scale sentry
    ...........
    Some time later, scale the app
    you build
    VS

    View Slide

  66. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........
    Scale sentry
    ...........
    Some time later, scale the app
    you build
    Install Sentry
    VS

    View Slide

  67. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........
    Scale sentry
    ...........
    Some time later, scale the app
    you build
    Install Sentry
    Send lots of data to Sentry Service
    VS

    View Slide

  68. In the real world
    Install Sentry
    Send lots of data
    ...........
    Crash sentry
    ...........
    Scale sentry
    ...........
    Some time later, scale the app
    you build
    Install Sentry
    Send lots of data to Sentry Service
    Let David Cramer scale Sentry
    VS

    View Slide

  69. App
    App
    App
    Support
    Knowledge Base
    Billing
    Where to Start
    App
    App
    App
    Marketing
    Analytics
    Mobile
    App
    App
    App
    API
    Front End
    Social

    View Slide

  70. App
    App
    Support
    Knowledge Base
    Billing
    Where to Start
    App
    Marketing
    Analytics
    Mobile App
    API
    Front End
    Social

    View Slide

  71. View Slide

  72. View Slide

  73. View Slide

  74. View Slide

  75. View Slide

  76. View Slide

  77. View Slide

  78. View Slide

  79. Service
    App

    View Slide

  80. Service
    App
    Models
    Views
    URLs
    Provider Endpoint Contract

    View Slide

  81. Take aways

    View Slide

  82. Take aways
    1. Start non-critical (Cheat)
    2. Create services where theres pain
    3. Start small

    View Slide

  83. Fin.
    Resources
    http://www.craigkerstiens.com
    http://bit.ly/djangoappstoservices
    http://www.12factor.net

    View Slide