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

What's hot (20)

Buffer - Seed round - Pitch Deck
Buffer - Seed round - Pitch DeckBuffer - Seed round - Pitch Deck
Buffer - Seed round - Pitch Deck
 
Neo4j: Data Engineering for RAG (retrieval augmented generation)
Neo4j: Data Engineering for RAG (retrieval augmented generation)Neo4j: Data Engineering for RAG (retrieval augmented generation)
Neo4j: Data Engineering for RAG (retrieval augmented generation)
 
The Nuances of Tokenization: A brief explanation on attempts from this past d...
The Nuances of Tokenization: A brief explanation on attempts from this past d...The Nuances of Tokenization: A brief explanation on attempts from this past d...
The Nuances of Tokenization: A brief explanation on attempts from this past d...
 
Polkadot Presentation
Polkadot PresentationPolkadot Presentation
Polkadot Presentation
 
Pitch Deck Teardown: Oii.ai's $1.9M Seed deck
Pitch Deck Teardown: Oii.ai's $1.9M Seed deckPitch Deck Teardown: Oii.ai's $1.9M Seed deck
Pitch Deck Teardown: Oii.ai's $1.9M Seed deck
 
Non fungible token(nf ts)
Non fungible token(nf ts)Non fungible token(nf ts)
Non fungible token(nf ts)
 
Tracxn - Top Business Models - Transportation and Logistics Tech - 19 May 2022
Tracxn - Top Business Models - Transportation and Logistics Tech - 19 May 2022Tracxn - Top Business Models - Transportation and Logistics Tech - 19 May 2022
Tracxn - Top Business Models - Transportation and Logistics Tech - 19 May 2022
 
Web3 Full Stack Development
Web3 Full Stack DevelopmentWeb3 Full Stack Development
Web3 Full Stack Development
 
Concord Business Plans - Pitch Deck Examples
Concord Business Plans - Pitch Deck ExamplesConcord Business Plans - Pitch Deck Examples
Concord Business Plans - Pitch Deck Examples
 
Lecture 10: ML Testing & Explainability (Full Stack Deep Learning - Spring 2021)
Lecture 10: ML Testing & Explainability (Full Stack Deep Learning - Spring 2021)Lecture 10: ML Testing & Explainability (Full Stack Deep Learning - Spring 2021)
Lecture 10: ML Testing & Explainability (Full Stack Deep Learning - Spring 2021)
 
Metaverse and Digital Twins on Enterprise-Public.pdf
Metaverse and Digital Twins on Enterprise-Public.pdfMetaverse and Digital Twins on Enterprise-Public.pdf
Metaverse and Digital Twins on Enterprise-Public.pdf
 
Pitch Deck Teardown: Faye's $10M Series A deck
Pitch Deck Teardown: Faye's $10M Series A deckPitch Deck Teardown: Faye's $10M Series A deck
Pitch Deck Teardown: Faye's $10M Series A deck
 
Accenture Life & Annuity Analytics—Use Cases
Accenture Life & Annuity Analytics—Use CasesAccenture Life & Annuity Analytics—Use Cases
Accenture Life & Annuity Analytics—Use Cases
 
Tafari Capital Investor Pitch Deck
Tafari Capital Investor Pitch DeckTafari Capital Investor Pitch Deck
Tafari Capital Investor Pitch Deck
 
Shihtzu Exchange, NFT Minting & Metaverse Platform
Shihtzu Exchange, NFT Minting & Metaverse PlatformShihtzu Exchange, NFT Minting & Metaverse Platform
Shihtzu Exchange, NFT Minting & Metaverse Platform
 
Ofoq pitch deck
Ofoq pitch deckOfoq pitch deck
Ofoq pitch deck
 
AI App Pitch Deck
AI App Pitch DeckAI App Pitch Deck
AI App Pitch Deck
 
VIOS - healthtech saas startup pitch deck presentation
VIOS - healthtech saas startup pitch deck presentationVIOS - healthtech saas startup pitch deck presentation
VIOS - healthtech saas startup pitch deck presentation
 
What is the Metaverse?
What is the Metaverse?What is the Metaverse?
What is the Metaverse?
 
Approximate nearest neighbor methods and vector models – NYC ML meetup
Approximate nearest neighbor methods and vector models – NYC ML meetupApproximate nearest neighbor methods and vector models – NYC ML meetup
Approximate nearest neighbor methods and vector models – NYC ML meetup
 

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 - Test
Kiran Naiga
 
locotalk-whitepaper-2016
locotalk-whitepaper-2016locotalk-whitepaper-2016
locotalk-whitepaper-2016
Anthony Wijnen
 
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
vrickens
 
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
write31
 
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
Deborah Gastineau
 

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

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
anilsa9823
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 

Recently uploaded (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
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 ...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

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.