SlideShare a Scribd company logo
1 of 36
Download to read offline
Managing Large Flask
Applications on Google App
Engine (GAE)
Emmanuel Olowosulu & Yemisi Obielodan
PyConNG 2018
Emmanuel
Olowosulu
CTO, Formplus
@seyisulu
o Also, software developer with
experience building Flask
applications and community builder.
Yemisi
Obielodan
Product Manager, Formplus
@ye_misi
o Over 8 years experience consulting
and building production apps with a
variety of stacks and technologies.
o Formplus is a cloud-based
data collection software as a
service. We help businesses
gather data from their users
who are online and offline,
analyze the data and then
help them make data-driven
decisions from it.
o Also a fun place to work.
o Python 2.7
o Flask
o Google App Engine
o Cloud Datastore
o Cloud Tasks
o AngularJS 1.5
(don’t judge !)
Our Stack
What We Will Be Covering
OVERVIEW
Large applications,
Flask and Google App
Engine
FLASK
Flask application
structure, blueprints
and request routing
APP
ENGINE
App Engine, Cloud
Datastore and the
Google Cloud Platform
SCALING
Performance, effective
GCP utilization,
problems
QUESTIONS
?
Overview
Large applications, Flask and Google App Engine
What is a Large
Application?
o Large number of users
o High requests/second
o Distributed servers
o Large data volume
Flask
Framework
o Flask is a micro web
framework written in
Python
o Supports extensions for
additional functionality
o Compatible with Google
App Engine
Google App
Engine
o GAE is a web
framework and cloud
computing platform for
developing and hosting
web applications in
Google-managed data
centers
o Applications are
sandboxed and run
across multiple servers
Flask
Flask application structure, blueprints and request routing
Flask Application Structure
o Large Flask apps should be broken down into
microservices. There should be at least two: the
frontend handling user facing requests and backend
handling longer running data and event processing.
o This ensures that the application is responsive.
o Also, there is nothing micro about microservices; the
frontend and backend may be monoliths themselves and
could benefit from refactoring.
Flask Structure
w/Blueprints
o In the structure shown, each
directory represents a
microservice
o In each microservice, group
related functionality using
Blueprints: the blog
microservice has frontend and
backend Blueprints
o App Engine handles requests
using rules contained in
dispatch.yaml
Flask Blueprints
Flask app
Frontend
blueprint
App Engine
dispatch file
Monorepo vs Multirepo
o Microservice purist may insist on having different
repositories for each microservice but we have had
success with a Monorepo.
o There are pros and cons associated with both
approaches and a Multirepo is better suited for large
teams each working on distinct microservices.
o Also, Conway’s Law: software ends up "shaped like" the
organizational structure it's designed in.
organizations which design
systems ... are constrained
to produce designs which
are copies of the
communication structures
of these organizations.
Conway’s Law
In Flask there are two
ways to create routes:
class based and function
based. A lot of people are
familiar with the latter but
using the class based
method can lead to better
code organization as you
can use inheritance to
share functionality
between routes.
Request Routing
App Engine
App Engine, Cloud Datastore and the Google Cloud Platform
App Engine & Google Cloud Platform
Image credits: https://cloud.google.com/appengine/
Cloud Storage
o Google Cloud Storage is file storage solution intended
for developers and system admins and has APIs allowing
apps to store and retrieve objects. It features global
edge-caching, versioning, OAuth and granular access
controls, configurable security, etc.
Cloud CDN
o Google Cloud CDN (Content Delivery Network) uses
Google's servers worldwide to load balanced content
close to your users. This provides faster delivery of
content to your users and reduces serving costs.
o App Engine also automatically pushes application assets
to Cloud CDN on deployment.
Cloud Tasks
o Task queues let applications do work, asynchronously
outside of a user request. If an app needs to execute
work in the background, it adds tasks to task queues.
The tasks are executed later, by worker services. Task
queues come in two flavors, push and pull.
o Push queues run tasks by delivering HTTP requests to
App Engine worker services.
o Pull queues rely on other worker services to fetch tasks
from the queue on their own.
Cloud Pub/Sub
o Cloud Pub/Sub is a fully-managed real-time messaging
service that allows you to send and receive messages
between independent applications.
o Pub/Sub broadcasts messages from publishers to
subscribers via channels. Many subscribers can
subscribe to the same channel.
o Allows the decoupling of background, long running data
and event processing from user-facing requests.
Cloud Dataflow
o Cloud Dataflow is a fully-managed service for
transforming and enriching data in stream (real time)
and batch (historical) modes. Cloud Dataflow seamlessly
integrates with GCP services for streaming events
ingestion (Cloud Pub/Sub), data warehousing
(BigQuery), and more.
Google BigQuery
o BigQuery is Google's serverless, highly scalable,
enterprise cloud data warehouse. It is fast, cost-
effective, fully managed and can be used for analytics. It
also has built-in machine learning (beta).
o BigQuery is used for Online Analytical Processing
(OLAP): generating reports, time series and trend
analysis views and can be paired with Business
Intelligence (BI) tools like Metabase or Google Data
Studio (beta).
Cloud Datastore
o Cloud Datastore is a highly-scalable NoSQL database for
your web and mobile applications.
o Datastore is to App Engine what MongoDB is to the
MEAN stack and to App Engine what MySQL is to the
LAMP stack.
o It is a highly-scalable NoSQL database for your
applications. Cloud Datastore automatically handles
sharding and replication, providing you with a highly
available and durable database that scales
automatically.
Datastore vs. MongoDB vs. MySQL
Datastore
oCategory of object:
Kind
oOne object:
Entity
oIndividual object data:
Property
oUnique ID for object:
Key
MongoDB
oCategory of object
Collection
oOne object
Document
oIndividual object data
Field
oUnique ID for object
Key
MySQL
statementoCategory of object:
Table
oOne object:
Row
oIndividual object data:
Column
oUnique ID for object:
Primary Key
NoSQL SQL
Merits of Using
App Engine
App Engine is similar to Heroku
o Platform as a Service (PaaS)
o Provide abstracted machine
instances to run your code
o Prevent you from worrying
about ops: infrastructure
upgrades, software updates
and security patches
o Automatic load balancing,
scaling and fault tolerance
Google App Engine
o Task queues let applications do work, asynchronously
outside of a user request. If an app needs to execute
work in the background, it adds tasks to task queues.
The tasks are executed later, by worker services. Task
queues come in two flavors, push and pull.
o Push queues run tasks by delivering HTTP requests to
App Engine worker services.
o Pull queues rely on other worker services to fetch tasks
from the queue on their own.
Scaling
Performance, effective GCP utilization,problems
- Pete Edochie
He who thinks the
soup is too much for the
eba cannot handle
greatness scale.
Problem 1: Out of Memory Errors
Background
Some tasks are
unable to be
completed because
they ran out of
memory.
One of what we’ve
found causes this
error is
communicating
with Sheets.
Cause
A library used consumed
~30MB per instance
when created and
instances cannot be
reused across requests.
This resulted in OOM
Errors when serving a lot
of requests to update
Google Sheets.
Solution
Cloud Functions
We recently refactored
the part of our code that
updates users
spreadsheets to use a
Cloud Function.
This means the
additional memory used
does not affect
subsequent requests.
- Phil Karlton
There are only two hard
things in Computer
Science: cache
invalidation and naming
things.
Problem 2: Cache Invalidation
Background
Users not having
their monthly
submissions quota
reset
Cause
When updating a large
number of entities in
Cloud Datastore, the
recommended approach
is to use Datastore
Migrations Pipelines.
Batching Datastore
writes for efficiency
bypassed Memcache and
that stale data could
potentially overwrite the
Datastore update.
Solution
Skip the in-process
cache but update
Memcache and
Datastore.
Use transactions when
modifying entities likely
to be updated in the
datastore but outdated
in the Memcache.
Datastore
Contention
Problem 3: Datastore Contention
Background
Updating form
submission count
for high traffic
forms
Cause
A job was created on the
submissions task queue
for each submission and
they all tried to update
the same entity at the
same time.
Solution
When the submission
comes in, a task is
created named with the
form ID and the time of
submission and then we
schedule it to run in
future.
We combine this with
an entity in datastore
that holds the
submission status for
that task to batch
updates.
Questions
???

More Related Content

What's hot

Requirements engineering for agile methods
Requirements engineering for agile methodsRequirements engineering for agile methods
Requirements engineering for agile methodsSyed Zaid Irshad
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesionSutha31
 
Software Testing and Quality Assurance Assignment 2
Software Testing and Quality Assurance Assignment 2Software Testing and Quality Assurance Assignment 2
Software Testing and Quality Assurance Assignment 2Gurpreet singh
 
Software maintenance ppt
Software maintenance pptSoftware maintenance ppt
Software maintenance pptAnas Usman
 
Software Configuration Management
Software Configuration ManagementSoftware Configuration Management
Software Configuration ManagementChandan Chaurasia
 
Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)ShudipPal
 
Prototype model
Prototype modelPrototype model
Prototype modelsadhana8
 
Chapter 15 software product metrics
Chapter 15 software product metricsChapter 15 software product metrics
Chapter 15 software product metricsSHREEHARI WADAWADAGI
 
Software reliability engineering
Software reliability engineeringSoftware reliability engineering
Software reliability engineeringMark Turner CRP
 
Design Concept software engineering
Design Concept software engineeringDesign Concept software engineering
Design Concept software engineeringDarshit Metaliya
 
Agile vs Iterative vs Waterfall models
Agile vs Iterative vs Waterfall models Agile vs Iterative vs Waterfall models
Agile vs Iterative vs Waterfall models Marraju Bollapragada V
 
Lect3 conventional vs modern spm
Lect3 conventional vs modern spmLect3 conventional vs modern spm
Lect3 conventional vs modern spmmeena466141
 
Software quality assurance activites
Software quality assurance activitesSoftware quality assurance activites
Software quality assurance activitesGolu Gupta
 
Improving software economics
Improving software economicsImproving software economics
Improving software economicsdeep sharma
 
IT Quality Testing and the Defect Management Process
IT Quality Testing and the Defect Management ProcessIT Quality Testing and the Defect Management Process
IT Quality Testing and the Defect Management ProcessYolanda Williams
 
Software Engineering - Ch17
Software Engineering - Ch17Software Engineering - Ch17
Software Engineering - Ch17Siddharth Ayer
 

What's hot (20)

Requirements engineering for agile methods
Requirements engineering for agile methodsRequirements engineering for agile methods
Requirements engineering for agile methods
 
Coupling and cohesion
Coupling and cohesionCoupling and cohesion
Coupling and cohesion
 
Software Testing and Quality Assurance Assignment 2
Software Testing and Quality Assurance Assignment 2Software Testing and Quality Assurance Assignment 2
Software Testing and Quality Assurance Assignment 2
 
Software maintenance ppt
Software maintenance pptSoftware maintenance ppt
Software maintenance ppt
 
Software Configuration Management
Software Configuration ManagementSoftware Configuration Management
Software Configuration Management
 
Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)Software Engineering (Introduction to Software Engineering)
Software Engineering (Introduction to Software Engineering)
 
Prototype model
Prototype modelPrototype model
Prototype model
 
Chapter 15 software product metrics
Chapter 15 software product metricsChapter 15 software product metrics
Chapter 15 software product metrics
 
Virtualization
Virtualization Virtualization
Virtualization
 
Software reliability engineering
Software reliability engineeringSoftware reliability engineering
Software reliability engineering
 
Design Concept software engineering
Design Concept software engineeringDesign Concept software engineering
Design Concept software engineering
 
Software Evolution
Software EvolutionSoftware Evolution
Software Evolution
 
Software development process models
Software development process modelsSoftware development process models
Software development process models
 
Agile vs Iterative vs Waterfall models
Agile vs Iterative vs Waterfall models Agile vs Iterative vs Waterfall models
Agile vs Iterative vs Waterfall models
 
Lect3 conventional vs modern spm
Lect3 conventional vs modern spmLect3 conventional vs modern spm
Lect3 conventional vs modern spm
 
Compatibility Testing
Compatibility TestingCompatibility Testing
Compatibility Testing
 
Software quality assurance activites
Software quality assurance activitesSoftware quality assurance activites
Software quality assurance activites
 
Improving software economics
Improving software economicsImproving software economics
Improving software economics
 
IT Quality Testing and the Defect Management Process
IT Quality Testing and the Defect Management ProcessIT Quality Testing and the Defect Management Process
IT Quality Testing and the Defect Management Process
 
Software Engineering - Ch17
Software Engineering - Ch17Software Engineering - Ch17
Software Engineering - Ch17
 

Similar to Managing Large Flask Applications On Google App Engine (GAE)

Amplitude wave architecture - Test
Amplitude wave architecture - TestAmplitude wave architecture - Test
Amplitude wave architecture - TestKiran Naiga
 
locotalk-whitepaper-2016
locotalk-whitepaper-2016locotalk-whitepaper-2016
locotalk-whitepaper-2016Anthony Wijnen
 
Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021NeerajKumar1965
 
OCC Overview OMG Clouds Meeting 07-13-09 v3
OCC Overview OMG Clouds Meeting 07-13-09 v3OCC Overview OMG Clouds Meeting 07-13-09 v3
OCC Overview OMG Clouds Meeting 07-13-09 v3Robert Grossman
 
Over view of Technologies
Over view of TechnologiesOver view of Technologies
Over view of TechnologiesChris Mitchell
 
Meteor Mobile App Development
Meteor Mobile App DevelopmentMeteor Mobile App Development
Meteor Mobile App DevelopmentSanjay Kumar
 
AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)Alex Ross
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computingwebscale
 
IT 8003 Cloud ComputingFor this activi.docx
IT 8003 Cloud ComputingFor this activi.docxIT 8003 Cloud ComputingFor this activi.docx
IT 8003 Cloud ComputingFor this activi.docxvrickens
 
MongoDB .local Chicago 2019: MongoDB – Powering the new age data demands
MongoDB .local Chicago 2019: MongoDB – Powering the new age data demandsMongoDB .local Chicago 2019: MongoDB – Powering the new age data demands
MongoDB .local Chicago 2019: MongoDB – Powering the new age data demandsMongoDB
 
COMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docxCOMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docxwrite31
 
Technology Overview
Technology OverviewTechnology Overview
Technology OverviewLiran Zelkha
 
Online productivity tools - SILS20090
Online productivity tools - SILS20090Online productivity tools - SILS20090
Online productivity tools - SILS20090is20090
 
HLayer / Cloud Native Best Practices
HLayer / Cloud Native Best PracticesHLayer / Cloud Native Best Practices
HLayer / Cloud Native Best PracticesAymen EL Amri
 
The Recent Pronouncement Of The World Wide Web (Www) Had
The Recent Pronouncement Of The World Wide Web (Www) HadThe Recent Pronouncement Of The World Wide Web (Www) Had
The Recent Pronouncement Of The World Wide Web (Www) HadDeborah Gastineau
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docxfantabulous2024
 

Similar to Managing Large Flask Applications On Google App Engine (GAE) (20)

Amplitude wave architecture - Test
Amplitude wave architecture - TestAmplitude wave architecture - Test
Amplitude wave architecture - Test
 
locotalk-whitepaper-2016
locotalk-whitepaper-2016locotalk-whitepaper-2016
locotalk-whitepaper-2016
 
Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021
 
OCC Overview OMG Clouds Meeting 07-13-09 v3
OCC Overview OMG Clouds Meeting 07-13-09 v3OCC Overview OMG Clouds Meeting 07-13-09 v3
OCC Overview OMG Clouds Meeting 07-13-09 v3
 
Over view of Technologies
Over view of TechnologiesOver view of Technologies
Over view of Technologies
 
Meteor Mobile App Development
Meteor Mobile App DevelopmentMeteor Mobile App Development
Meteor Mobile App Development
 
Symphony Driver Essay
Symphony Driver EssaySymphony Driver Essay
Symphony Driver Essay
 
Final paper
Final paperFinal paper
Final paper
 
AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)AngularJS in Production (CTO Forum)
AngularJS in Production (CTO Forum)
 
Cloud Computing
Cloud ComputingCloud Computing
Cloud Computing
 
IT 8003 Cloud ComputingFor this activi.docx
IT 8003 Cloud ComputingFor this activi.docxIT 8003 Cloud ComputingFor this activi.docx
IT 8003 Cloud ComputingFor this activi.docx
 
MongoDB .local Chicago 2019: MongoDB – Powering the new age data demands
MongoDB .local Chicago 2019: MongoDB – Powering the new age data demandsMongoDB .local Chicago 2019: MongoDB – Powering the new age data demands
MongoDB .local Chicago 2019: MongoDB – Powering the new age data demands
 
COMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docxCOMP6210 Web Services And Design Methodologies.docx
COMP6210 Web Services And Design Methodologies.docx
 
Technology Overview
Technology OverviewTechnology Overview
Technology Overview
 
Online productivity tools - SILS20090
Online productivity tools - SILS20090Online productivity tools - SILS20090
Online productivity tools - SILS20090
 
HLayer / Cloud Native Best Practices
HLayer / Cloud Native Best PracticesHLayer / Cloud Native Best Practices
HLayer / Cloud Native Best Practices
 
The Recent Pronouncement Of The World Wide Web (Www) Had
The Recent Pronouncement Of The World Wide Web (Www) HadThe Recent Pronouncement Of The World Wide Web (Www) Had
The Recent Pronouncement Of The World Wide Web (Www) Had
 
About clouds
About cloudsAbout clouds
About clouds
 
592-1627-1-PB
592-1627-1-PB592-1627-1-PB
592-1627-1-PB
 
Company Visitor Management System Report.docx
Company Visitor Management System Report.docxCompany Visitor Management System Report.docx
Company Visitor Management System Report.docx
 

Recently uploaded

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 

Recently uploaded (20)

Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 

Managing Large Flask Applications On Google App Engine (GAE)

  • 1. Managing Large Flask Applications on Google App Engine (GAE) Emmanuel Olowosulu & Yemisi Obielodan PyConNG 2018
  • 2. Emmanuel Olowosulu CTO, Formplus @seyisulu o Also, software developer with experience building Flask applications and community builder. Yemisi Obielodan Product Manager, Formplus @ye_misi o Over 8 years experience consulting and building production apps with a variety of stacks and technologies.
  • 3. o Formplus is a cloud-based data collection software as a service. We help businesses gather data from their users who are online and offline, analyze the data and then help them make data-driven decisions from it. o Also a fun place to work.
  • 4. o Python 2.7 o Flask o Google App Engine o Cloud Datastore o Cloud Tasks o AngularJS 1.5 (don’t judge !) Our Stack
  • 5. What We Will Be Covering OVERVIEW Large applications, Flask and Google App Engine FLASK Flask application structure, blueprints and request routing APP ENGINE App Engine, Cloud Datastore and the Google Cloud Platform SCALING Performance, effective GCP utilization, problems QUESTIONS ?
  • 6. Overview Large applications, Flask and Google App Engine
  • 7. What is a Large Application? o Large number of users o High requests/second o Distributed servers o Large data volume
  • 8. Flask Framework o Flask is a micro web framework written in Python o Supports extensions for additional functionality o Compatible with Google App Engine
  • 9. Google App Engine o GAE is a web framework and cloud computing platform for developing and hosting web applications in Google-managed data centers o Applications are sandboxed and run across multiple servers
  • 10. Flask Flask application structure, blueprints and request routing
  • 11. Flask Application Structure o Large Flask apps should be broken down into microservices. There should be at least two: the frontend handling user facing requests and backend handling longer running data and event processing. o This ensures that the application is responsive. o Also, there is nothing micro about microservices; the frontend and backend may be monoliths themselves and could benefit from refactoring.
  • 12. Flask Structure w/Blueprints o In the structure shown, each directory represents a microservice o In each microservice, group related functionality using Blueprints: the blog microservice has frontend and backend Blueprints o App Engine handles requests using rules contained in dispatch.yaml
  • 14. Monorepo vs Multirepo o Microservice purist may insist on having different repositories for each microservice but we have had success with a Monorepo. o There are pros and cons associated with both approaches and a Multirepo is better suited for large teams each working on distinct microservices. o Also, Conway’s Law: software ends up "shaped like" the organizational structure it's designed in.
  • 15. organizations which design systems ... are constrained to produce designs which are copies of the communication structures of these organizations. Conway’s Law
  • 16. In Flask there are two ways to create routes: class based and function based. A lot of people are familiar with the latter but using the class based method can lead to better code organization as you can use inheritance to share functionality between routes. Request Routing
  • 17. App Engine App Engine, Cloud Datastore and the Google Cloud Platform
  • 18. App Engine & Google Cloud Platform Image credits: https://cloud.google.com/appengine/
  • 19. Cloud Storage o Google Cloud Storage is file storage solution intended for developers and system admins and has APIs allowing apps to store and retrieve objects. It features global edge-caching, versioning, OAuth and granular access controls, configurable security, etc.
  • 20. Cloud CDN o Google Cloud CDN (Content Delivery Network) uses Google's servers worldwide to load balanced content close to your users. This provides faster delivery of content to your users and reduces serving costs. o App Engine also automatically pushes application assets to Cloud CDN on deployment.
  • 21. Cloud Tasks o Task queues let applications do work, asynchronously outside of a user request. If an app needs to execute work in the background, it adds tasks to task queues. The tasks are executed later, by worker services. Task queues come in two flavors, push and pull. o Push queues run tasks by delivering HTTP requests to App Engine worker services. o Pull queues rely on other worker services to fetch tasks from the queue on their own.
  • 22. Cloud Pub/Sub o Cloud Pub/Sub is a fully-managed real-time messaging service that allows you to send and receive messages between independent applications. o Pub/Sub broadcasts messages from publishers to subscribers via channels. Many subscribers can subscribe to the same channel. o Allows the decoupling of background, long running data and event processing from user-facing requests.
  • 23. Cloud Dataflow o Cloud Dataflow is a fully-managed service for transforming and enriching data in stream (real time) and batch (historical) modes. Cloud Dataflow seamlessly integrates with GCP services for streaming events ingestion (Cloud Pub/Sub), data warehousing (BigQuery), and more.
  • 24. Google BigQuery o BigQuery is Google's serverless, highly scalable, enterprise cloud data warehouse. It is fast, cost- effective, fully managed and can be used for analytics. It also has built-in machine learning (beta). o BigQuery is used for Online Analytical Processing (OLAP): generating reports, time series and trend analysis views and can be paired with Business Intelligence (BI) tools like Metabase or Google Data Studio (beta).
  • 25. Cloud Datastore o Cloud Datastore is a highly-scalable NoSQL database for your web and mobile applications. o Datastore is to App Engine what MongoDB is to the MEAN stack and to App Engine what MySQL is to the LAMP stack. o It is a highly-scalable NoSQL database for your applications. Cloud Datastore automatically handles sharding and replication, providing you with a highly available and durable database that scales automatically.
  • 26. Datastore vs. MongoDB vs. MySQL Datastore oCategory of object: Kind oOne object: Entity oIndividual object data: Property oUnique ID for object: Key MongoDB oCategory of object Collection oOne object Document oIndividual object data Field oUnique ID for object Key MySQL statementoCategory of object: Table oOne object: Row oIndividual object data: Column oUnique ID for object: Primary Key NoSQL SQL
  • 27. Merits of Using App Engine App Engine is similar to Heroku o Platform as a Service (PaaS) o Provide abstracted machine instances to run your code o Prevent you from worrying about ops: infrastructure upgrades, software updates and security patches o Automatic load balancing, scaling and fault tolerance
  • 28. Google App Engine o Task queues let applications do work, asynchronously outside of a user request. If an app needs to execute work in the background, it adds tasks to task queues. The tasks are executed later, by worker services. Task queues come in two flavors, push and pull. o Push queues run tasks by delivering HTTP requests to App Engine worker services. o Pull queues rely on other worker services to fetch tasks from the queue on their own.
  • 29. Scaling Performance, effective GCP utilization,problems
  • 30. - Pete Edochie He who thinks the soup is too much for the eba cannot handle greatness scale.
  • 31. Problem 1: Out of Memory Errors Background Some tasks are unable to be completed because they ran out of memory. One of what we’ve found causes this error is communicating with Sheets. Cause A library used consumed ~30MB per instance when created and instances cannot be reused across requests. This resulted in OOM Errors when serving a lot of requests to update Google Sheets. Solution Cloud Functions We recently refactored the part of our code that updates users spreadsheets to use a Cloud Function. This means the additional memory used does not affect subsequent requests.
  • 32. - Phil Karlton There are only two hard things in Computer Science: cache invalidation and naming things.
  • 33. Problem 2: Cache Invalidation Background Users not having their monthly submissions quota reset Cause When updating a large number of entities in Cloud Datastore, the recommended approach is to use Datastore Migrations Pipelines. Batching Datastore writes for efficiency bypassed Memcache and that stale data could potentially overwrite the Datastore update. Solution Skip the in-process cache but update Memcache and Datastore. Use transactions when modifying entities likely to be updated in the datastore but outdated in the Memcache.
  • 35. Problem 3: Datastore Contention Background Updating form submission count for high traffic forms Cause A job was created on the submissions task queue for each submission and they all tried to update the same entity at the same time. Solution When the submission comes in, a task is created named with the form ID and the time of submission and then we schedule it to run in future. We combine this with an entity in datastore that holds the submission status for that task to batch updates.