Build, deploy and scale: Django, GraphQL and SPA @dhilipsiva
@dhilipsiva ● Optimistic Nihilist ● Democratic Socialist ● I code for fun & profit ● I love Science, Python, FOSS & தமிழ் ● Dad of 2. Environmentalist. Story Teller. Gamer. ● Jack of all trades & Master of none ● A volunteer for progressives
I have no idea what I am talking about 🤪
Credentials ● 11+ years of professional experience in python ● Built over 20 different products using django alone ● Scaled more than 5 products to serve millions of requests per second ● Built a Device Farm (iOS and Android) ● Involved in building a Bitcoin mining farm with Rpi + ASIC (aws for miners)
Profession VP of Engineering @ Reckonsys Hitoshīkage @ Nitimis
Why GraphQL? ● Much more standardized than the fragmented RESTful implementations ● Out-of-box live & browsable documentation ● No back-and-forth communication between API developer and SPA developer ● Precise queries
Let’s look at our (buggy ) demo app 😬 https://stackopenflow.space It is a very silly StackOverflow clone
Stack ● Python ● Django ● Graphene ● Django-graphql-jwt ● Django-rules ● postgres ● JavaScript ● React ● Relay ● easy-peasy
Graphene ● Custom field defs ● Syncronous ● Mature ● Status Quo ● Fantastic Django integration Strawberry.rocks ● Dataclasses ● Asyncronous ● Not-so-mature ● Future (maybe) ● Very minimal Django integration
Per-object perms ● Choose a rule based framework (like django- rules) over a DB-based framework (guardian) ● Less DB calls = less latency ● No unnecessary migrations gue to change in logic ● Easier to maintain
Why React? ● Plays really well with GraphQL (Facebook being a big proponent of both React and GraphQL) ● Can build native applications with react- native. So a front-end engineer can easily scale-up as a mobile application developer. ● Second only to vue.js in terms of community/popularity
Why Relay? ● Relay’s APIs are cleaner compared to Apollo ● Hooks are 1st class citizens ● Out of box caching support ● Backed by Facebook (just like GraphQL and React) so React has excellent integration. ● Relay-compiler is fantastic at catching errors
Why easy-peasy? ● Hooks are 1st class citizens ● Less boilerplate ● Pleasant APIs ● Ease of use
Project Layout ● All other django apps are placed under the django root “stackopenflow” app (the module that contains settings.py, urls.py, wsgi.py, etc) ● Therefore, all imports are namespaced with “stackopenflow”
Typical Modules ● admin.py ● apps.py ● models.py ● tests.py ● views.py
Our Modules ● admin.py ● apps.py ● behaviours.py ● choices.py ● inputs.py ● models.py ● mutations.py ● queries.py ● tests.py ● types.py
Let’s walk through the source code Django & React https://github.com/djconeu2021/stackopenflow-api https://github.com/djconeu2021/stackopenflow-app
bigga ● https://github.com/djconeu2021/bigga ● A docker-compose based deployment ● Can be configured to be used to docker-swarm with minimal changes ● Handy for local development too ● Suitable for cheap, non-production workloads ● Code walk through
AWS copilot ● https://aws.github.io/copilot-cli ● ECS on AWS Fargate (serverless containers) ● Very reliable & scaleable, but vendor dependent ● Easy auto scaling configuration ● Cheaper & faster than Lambda (serverless functions) ● But be sure set-up along with tools like Terraform
SPA Deployment ● S3 + CloudFront + ACM ● Cheaper than alternatives like Netlify ● Less latency ● Manual Setup: https://github.com/reckonsys/bigga/blob/community/S3_FRONTEND_DEPLOYMENT.md ● Pyinvoke Script: https://github.com/reckonsys/bigga/blob/community/tasks.py
Thank You @dhilipsiva dhilipsiva@pm.me https://dhilipsiva.com https://t.me/dhilipsiva

Build, deploy and scale: Django, GraphQL and SPA (DjangoCon EU 2021)