SlideShare a Scribd company logo
DEPOT - STORY OF A FILE.WRITE() 
GONE WRONG 
Alessandro Molina 
@__amol__ 
amol@turbogears.org
Who am I 
● CTO @ AXANT.it, mostly Python company 
(with some iOS and Android) 
● TurboGears2 dev team member 
● Contributions to web world python libraries 
○ MING MongoDB ODM 
○ ToscaWidgets2 
○ Formencode
Background 
● Everything starts from a project which was 
just a POT with budget constraint. 
● Obviously it became the final product. 
● It saved and updated a lot of files, mostly 
images.
Technologies. 
● Short on budget: cloud storage was not an 
available choice 
● Short on time: developers choose to just 
store everything on disk and rely on nginx 
to serve them in a good enough manner
The Technical Consultant 
● Customer had a technical leader that 
enforced deployment decisions. 
● Customer decided production 
environment three days before the “go 
live” 
● Due to limited budget he decided they 
were not going to rent a server.
The product owner choice
Murphy Law 
● They went for Heroku free plan as PaaS 
● Heroku doesn’t support storing files on 
disk 
● The whole software did store files on disk
Ooops
Panic 
● The day before launch, team rewrote 30% 
of the software to switch saving files from 
disk to GridFS (app was mongodb based) 
● It was an huge hack based on 
monkeypatching the attachment classes 
● It went online with practically no testing on 
the field.
The day after 
● After emergency has been solved it was 
clear that we needed a better way to 
handle such issues. 
● We decided to create a tool to solve the 
issue independently from the web 
development framekwork in use
PyConFR 2014 - DEPOT, Story of a file.write() gone wrong
DEPOT Requirements 
● Permit choosing between multiple storage 
engines just by changing a configuration 
file 
● Permit switching storage engine at runtime 
without breaking past files 
● Permit to concurrently use multiple 
storages
Multiple Storages 
● One “default” storage, any other storage 
can be promoted to default, anytime. 
● When uploading a file it goes to the 
default storage unless otherwise specified. 
● Each storage has a name, files can be 
uniquely identified among storages by 
storage_name/fileid.
DepotManager 
● The DepotManager is the single interface 
to DEPOT. 
● It tracks the active storages, the default 
one, and the WSGI middleware. 
● To work on a storage just get it from the 
DepotManager.
Easy to Use 
● Simple things should be simple 
from depot.manager import DepotManager 
# Configure a *default* depot to store files on MongoDB 
GridFS 
DepotManager.configure('default', { 
'depot.backend': 'depot.io.gridfs.GridFSStorage', 
'depot.mongouri': 'mongodb://localhost/db' 
}) 
depot = DepotManager.get() 
# Save the file and get the fileid 
fileid = depot.create(open('/tmp/file.png')) 
# Get the file back 
stored_file = depot.get(fileid) 
print stored_file.filename 
print stored_file.content_type
With Batteries 
● Complex things should be straightforward 
from depot.fields.sqlalchemy import UploadedFileField 
from depot.fields.specialized.image import UploadedImageWithThumb 
class Document(Base): 
__tablename__ = 'document' 
uid = Column(Integer, autoincrement=True, primary_key=True) 
name = Column(Unicode(16), unique=True) 
# photo field will automatically generate thumbnail 
photo = Column(UploadedFileField(upload_type=UploadedImageWithThumb)) 
# Store documents with attached files, the source can be a file or bytes 
doc = Document(name=u'Foo', 
content=b'TEXT CONTENT STORED AS FILE', 
photo=open('/tmp/file.png'))
No environment constraints 
● Attachment field for SQLAlchemy 
● Attachment field for MongoDB 
● Bultin support for S3, LocalFiles and 
GridFS 
● Delivery of files happens on a plain WSGI 
middleware compatible with any web 
framework.
Copes with Database 
● Transactions rollback should delete newly 
uploaded files and recover the previous 
ones. 
● Deleting an item deletes attached files 
(unless rollback happens)
Easy to Extend 
● Custom attachments can be easily created 
UploadedFileField(upload_type=UploadedImageWithMaxSize) 
● Filters can be applied to attachments 
UploadedFileField(filters=[WithThumbnailFilter()]) 
● Multiple filters can be applied (rescale 
image and create thumbnails)
Custom Attachments 
● Attachment Classes are in charge of 
storing the actually uploaded file 
● They can change the file before it’s 
uploaded. 
● They can add additional data and even 
behaviours to the file.
Filters 
● Each attachment can have multiple filters 
● They run after upload, so they can add 
metadata or generate new files but not 
replace the original one. 
● They can store additional metadata with 
the file, but not behaviours (methods).
And it’s WebScale™!
Web Application Friendly 
● Need to serve stored files? Just mount 
DepotManager.make_middleware around 
your app and start serving them. 
● If files are stored on a backend that 
supports HTTP, the user will be 
permanently redirected there by the 
middleware instead of serving files itself.
Made for the Web 
● Storage backends can provide public url 
for any CDN 
● File information common in HTTP are 
provided as properties out of the box 
○ content_type 
○ last_modified 
○ content_length 
○ filename
Feel free to try it! 
● Python 2.6, 2.7, 3.2, 3.3 and 3.4 
● pip install filedepot 
● Fully Documented https://depot. 
readthedocs.org 
● Tested with 100% coverage 
https://travis-ci.org/amol-/depot
Questions?
Ad

More Related Content

What's hot (20)

Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
Vanilla JS*
Vanilla JS*Vanilla JS*
Vanilla JS*
Théodore Biadala
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 
Rails入门培训
Rails入门培训Rails入门培训
Rails入门培训
ouyangzhiping
 
ITB2019 CacheBox + LogBox 101 - Brad Wood
ITB2019 CacheBox + LogBox 101 - Brad WoodITB2019 CacheBox + LogBox 101 - Brad Wood
ITB2019 CacheBox + LogBox 101 - Brad Wood
Ortus Solutions, Corp
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDB
Hengki Sihombing
 
Node in Real Time - The Beginning
Node in Real Time - The BeginningNode in Real Time - The Beginning
Node in Real Time - The Beginning
Axilis
 
Grunt All Day
Grunt All DayGrunt All Day
Grunt All Day
douglasknudsen
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
Derek Willian Stavis
 
Leading a Community-Driven Open Source Project
Leading a Community-Driven Open Source ProjectLeading a Community-Driven Open Source Project
Leading a Community-Driven Open Source Project
Vincent Massol
 
Custom gutenberg block development with React
Custom gutenberg block development with ReactCustom gutenberg block development with React
Custom gutenberg block development with React
Imran Sayed
 
Future of NodeJS
Future of NodeJSFuture of NodeJS
Future of NodeJS
Sébastien Pertus
 
Something about node basics
Something about node basicsSomething about node basics
Something about node basics
Philipp Fehre
 
NodeJS
NodeJSNodeJS
NodeJS
Alok Guha
 
Docker Up and Running for Web Developers
Docker Up and Running for Web DevelopersDocker Up and Running for Web Developers
Docker Up and Running for Web Developers
Amr Fawzy
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
Domenic Denicola
 
3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
F5 Buddy
 
Node js
Node jsNode js
Node js
Rohan Chandane
 
Nodejs intro
Nodejs introNodejs intro
Nodejs intro
Ndjido Ardo BAR
 
XWiki: The web's Swiss Army Knife
XWiki: The web's Swiss Army KnifeXWiki: The web's Swiss Army Knife
XWiki: The web's Swiss Army Knife
Vincent Massol
 
Event-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 EngineEvent-driven IO server-side JavaScript environment based on V8 Engine
Event-driven IO server-side JavaScript environment based on V8 Engine
Ricardo Silva
 
Scalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JSScalable network applications, event-driven - Node JS
Scalable network applications, event-driven - Node JS
Cosmin Mereuta
 
ITB2019 CacheBox + LogBox 101 - Brad Wood
ITB2019 CacheBox + LogBox 101 - Brad WoodITB2019 CacheBox + LogBox 101 - Brad Wood
ITB2019 CacheBox + LogBox 101 - Brad Wood
Ortus Solutions, Corp
 
Create a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDBCreate a RESTful API with NodeJS, Express and MongoDB
Create a RESTful API with NodeJS, Express and MongoDB
Hengki Sihombing
 
Node in Real Time - The Beginning
Node in Real Time - The BeginningNode in Real Time - The Beginning
Node in Real Time - The Beginning
Axilis
 
Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!Forget Grunt and Gulp! Webpack and NPM rule them all!
Forget Grunt and Gulp! Webpack and NPM rule them all!
Derek Willian Stavis
 
Leading a Community-Driven Open Source Project
Leading a Community-Driven Open Source ProjectLeading a Community-Driven Open Source Project
Leading a Community-Driven Open Source Project
Vincent Massol
 
Custom gutenberg block development with React
Custom gutenberg block development with ReactCustom gutenberg block development with React
Custom gutenberg block development with React
Imran Sayed
 
Something about node basics
Something about node basicsSomething about node basics
Something about node basics
Philipp Fehre
 
Docker Up and Running for Web Developers
Docker Up and Running for Web DevelopersDocker Up and Running for Web Developers
Docker Up and Running for Web Developers
Amr Fawzy
 
Understanding the Node.js Platform
Understanding the Node.js PlatformUnderstanding the Node.js Platform
Understanding the Node.js Platform
Domenic Denicola
 
3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
F5 Buddy
 
XWiki: The web's Swiss Army Knife
XWiki: The web's Swiss Army KnifeXWiki: The web's Swiss Army Knife
XWiki: The web's Swiss Army Knife
Vincent Massol
 

Similar to PyConFR 2014 - DEPOT, Story of a file.write() gone wrong (20)

EuroPython 2015 - Storing files for the web is not as straightforward as you ...
EuroPython 2015 - Storing files for the web is not as straightforward as you ...EuroPython 2015 - Storing files for the web is not as straightforward as you ...
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
Alessandro Molina
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
FITC
 
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering LabVoxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
Ron Munitz
 
Getting started with docker (2017)
Getting started with docker (2017)Getting started with docker (2017)
Getting started with docker (2017)
JEMLI Fathi
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
Hiroki Endo
 
CodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering labCodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering lab
Ron Munitz
 
Dockerfiles & Best Practices
Dockerfiles & Best PracticesDockerfiles & Best Practices
Dockerfiles & Best Practices
Avash Mulmi
 
Magento Docker Setup.pdf
Magento Docker Setup.pdfMagento Docker Setup.pdf
Magento Docker Setup.pdf
Abid Malik
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
Samuel Chow
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
Mono Repo
Mono RepoMono Repo
Mono Repo
Zacky Pickholz
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
GR8Conf
 
dkr_django_slides
dkr_django_slidesdkr_django_slides
dkr_django_slides
Gladson Manuel
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
NodeXperts
 
Docker Overview
Docker OverviewDocker Overview
Docker Overview
Gary Williams
 
Reproducibility in artificial intelligence
Reproducibility in artificial intelligenceReproducibility in artificial intelligence
Reproducibility in artificial intelligence
Carlos Toxtli
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser705051
 
Terraform-2.pdf
Terraform-2.pdfTerraform-2.pdf
Terraform-2.pdf
rutiksankapal21
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor Workshop
Velocidex Enterprises
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
 
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
EuroPython 2015 - Storing files for the web is not as straightforward as you ...EuroPython 2015 - Storing files for the web is not as straightforward as you ...
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
Alessandro Molina
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
FITC
 
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering LabVoxxed days Vilnius 2015 - Android Reverse Engineering Lab
Voxxed days Vilnius 2015 - Android Reverse Engineering Lab
Ron Munitz
 
Getting started with docker (2017)
Getting started with docker (2017)Getting started with docker (2017)
Getting started with docker (2017)
JEMLI Fathi
 
Introduction to docker
Introduction to dockerIntroduction to docker
Introduction to docker
Hiroki Endo
 
CodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering labCodeMotion tel aviv 2015 - android reverse engineering lab
CodeMotion tel aviv 2015 - android reverse engineering lab
Ron Munitz
 
Dockerfiles & Best Practices
Dockerfiles & Best PracticesDockerfiles & Best Practices
Dockerfiles & Best Practices
Avash Mulmi
 
Magento Docker Setup.pdf
Magento Docker Setup.pdfMagento Docker Setup.pdf
Magento Docker Setup.pdf
Abid Malik
 
Docker primer and tips
Docker primer and tipsDocker primer and tips
Docker primer and tips
Samuel Chow
 
Docker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and ContainersDocker 101 : Introduction to Docker and Containers
Docker 101 : Introduction to Docker and Containers
Yajushi Srivastava
 
My "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails ProjectsMy "Perfect" Toolchain Setup for Grails Projects
My "Perfect" Toolchain Setup for Grails Projects
GR8Conf
 
Improving build solutions dependency management with webpack
Improving build solutions  dependency management with webpackImproving build solutions  dependency management with webpack
Improving build solutions dependency management with webpack
NodeXperts
 
Reproducibility in artificial intelligence
Reproducibility in artificial intelligenceReproducibility in artificial intelligence
Reproducibility in artificial intelligence
Carlos Toxtli
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdfHashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser705051
 
Crikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor WorkshopCrikeycon 2019 Velociraptor Workshop
Crikeycon 2019 Velociraptor Workshop
Velocidex Enterprises
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Opersys inc.
 
Ad

More from Alessandro Molina (15)

PyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdfPyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdf
Alessandro Molina
 
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
Alessandro Molina
 
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESPyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
Alessandro Molina
 
PyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profitPyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profit
Alessandro Molina
 
PyConUK 2014 - PostMortem Debugging and Web Development Updated
PyConUK 2014 - PostMortem Debugging and Web Development UpdatedPyConUK 2014 - PostMortem Debugging and Web Development Updated
PyConUK 2014 - PostMortem Debugging and Web Development Updated
Alessandro Molina
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
Alessandro Molina
 
Post-Mortem Debugging and Web Development
Post-Mortem Debugging and Web DevelopmentPost-Mortem Debugging and Web Development
Post-Mortem Debugging and Web Development
Alessandro Molina
 
MongoTorino 2013 - BSON Mad Science for fun and profit
MongoTorino 2013 - BSON Mad Science for fun and profitMongoTorino 2013 - BSON Mad Science for fun and profit
MongoTorino 2013 - BSON Mad Science for fun and profit
Alessandro Molina
 
PyConUK2013 - Validated documents on MongoDB with Ming
PyConUK2013 - Validated documents on MongoDB with MingPyConUK2013 - Validated documents on MongoDB with Ming
PyConUK2013 - Validated documents on MongoDB with Ming
Alessandro Molina
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
Alessandro Molina
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
Alessandro Molina
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGears
Alessandro Molina
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2
Alessandro Molina
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
 
From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2
Alessandro Molina
 
PyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdfPyCon Ireland 2022 - PyArrow full stack.pdf
PyCon Ireland 2022 - PyArrow full stack.pdf
Alessandro Molina
 
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
Alessandro Molina
 
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATESPyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
Alessandro Molina
 
PyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profitPyConIT6 - Messing up with pymongo for fun and profit
PyConIT6 - Messing up with pymongo for fun and profit
Alessandro Molina
 
PyConUK 2014 - PostMortem Debugging and Web Development Updated
PyConUK 2014 - PostMortem Debugging and Web Development UpdatedPyConUK 2014 - PostMortem Debugging and Web Development Updated
PyConUK 2014 - PostMortem Debugging and Web Development Updated
Alessandro Molina
 
Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2Reactive & Realtime Web Applications with TurboGears2
Reactive & Realtime Web Applications with TurboGears2
Alessandro Molina
 
Post-Mortem Debugging and Web Development
Post-Mortem Debugging and Web DevelopmentPost-Mortem Debugging and Web Development
Post-Mortem Debugging and Web Development
Alessandro Molina
 
MongoTorino 2013 - BSON Mad Science for fun and profit
MongoTorino 2013 - BSON Mad Science for fun and profitMongoTorino 2013 - BSON Mad Science for fun and profit
MongoTorino 2013 - BSON Mad Science for fun and profit
Alessandro Molina
 
PyConUK2013 - Validated documents on MongoDB with Ming
PyConUK2013 - Validated documents on MongoDB with MingPyConUK2013 - Validated documents on MongoDB with Ming
PyConUK2013 - Validated documents on MongoDB with Ming
Alessandro Molina
 
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
Alessandro Molina
 
EuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears TrainingEuroPython 2013 - Python3 TurboGears Training
EuroPython 2013 - Python3 TurboGears Training
Alessandro Molina
 
PyGrunn2013 High Performance Web Applications with TurboGears
PyGrunn2013  High Performance Web Applications with TurboGearsPyGrunn2013  High Performance Web Applications with TurboGears
PyGrunn2013 High Performance Web Applications with TurboGears
Alessandro Molina
 
Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2Rapid Prototyping with TurboGears2
Rapid Prototyping with TurboGears2
Alessandro Molina
 
TurboGears2 Pluggable Applications
TurboGears2 Pluggable ApplicationsTurboGears2 Pluggable Applications
TurboGears2 Pluggable Applications
Alessandro Molina
 
From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2From SQLAlchemy to Ming with TurboGears2
From SQLAlchemy to Ming with TurboGears2
Alessandro Molina
 
Ad

Recently uploaded (20)

IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)Into The Box Conference Keynote Day 1 (ITB2025)
Into The Box Conference Keynote Day 1 (ITB2025)
Ortus Solutions, Corp
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 

PyConFR 2014 - DEPOT, Story of a file.write() gone wrong

  • 1. DEPOT - STORY OF A FILE.WRITE() GONE WRONG Alessandro Molina @__amol__ [email protected]
  • 2. Who am I ● CTO @ AXANT.it, mostly Python company (with some iOS and Android) ● TurboGears2 dev team member ● Contributions to web world python libraries ○ MING MongoDB ODM ○ ToscaWidgets2 ○ Formencode
  • 3. Background ● Everything starts from a project which was just a POT with budget constraint. ● Obviously it became the final product. ● It saved and updated a lot of files, mostly images.
  • 4. Technologies. ● Short on budget: cloud storage was not an available choice ● Short on time: developers choose to just store everything on disk and rely on nginx to serve them in a good enough manner
  • 5. The Technical Consultant ● Customer had a technical leader that enforced deployment decisions. ● Customer decided production environment three days before the “go live” ● Due to limited budget he decided they were not going to rent a server.
  • 7. Murphy Law ● They went for Heroku free plan as PaaS ● Heroku doesn’t support storing files on disk ● The whole software did store files on disk
  • 9. Panic ● The day before launch, team rewrote 30% of the software to switch saving files from disk to GridFS (app was mongodb based) ● It was an huge hack based on monkeypatching the attachment classes ● It went online with practically no testing on the field.
  • 10. The day after ● After emergency has been solved it was clear that we needed a better way to handle such issues. ● We decided to create a tool to solve the issue independently from the web development framekwork in use
  • 12. DEPOT Requirements ● Permit choosing between multiple storage engines just by changing a configuration file ● Permit switching storage engine at runtime without breaking past files ● Permit to concurrently use multiple storages
  • 13. Multiple Storages ● One “default” storage, any other storage can be promoted to default, anytime. ● When uploading a file it goes to the default storage unless otherwise specified. ● Each storage has a name, files can be uniquely identified among storages by storage_name/fileid.
  • 14. DepotManager ● The DepotManager is the single interface to DEPOT. ● It tracks the active storages, the default one, and the WSGI middleware. ● To work on a storage just get it from the DepotManager.
  • 15. Easy to Use ● Simple things should be simple from depot.manager import DepotManager # Configure a *default* depot to store files on MongoDB GridFS DepotManager.configure('default', { 'depot.backend': 'depot.io.gridfs.GridFSStorage', 'depot.mongouri': 'mongodb://localhost/db' }) depot = DepotManager.get() # Save the file and get the fileid fileid = depot.create(open('/tmp/file.png')) # Get the file back stored_file = depot.get(fileid) print stored_file.filename print stored_file.content_type
  • 16. With Batteries ● Complex things should be straightforward from depot.fields.sqlalchemy import UploadedFileField from depot.fields.specialized.image import UploadedImageWithThumb class Document(Base): __tablename__ = 'document' uid = Column(Integer, autoincrement=True, primary_key=True) name = Column(Unicode(16), unique=True) # photo field will automatically generate thumbnail photo = Column(UploadedFileField(upload_type=UploadedImageWithThumb)) # Store documents with attached files, the source can be a file or bytes doc = Document(name=u'Foo', content=b'TEXT CONTENT STORED AS FILE', photo=open('/tmp/file.png'))
  • 17. No environment constraints ● Attachment field for SQLAlchemy ● Attachment field for MongoDB ● Bultin support for S3, LocalFiles and GridFS ● Delivery of files happens on a plain WSGI middleware compatible with any web framework.
  • 18. Copes with Database ● Transactions rollback should delete newly uploaded files and recover the previous ones. ● Deleting an item deletes attached files (unless rollback happens)
  • 19. Easy to Extend ● Custom attachments can be easily created UploadedFileField(upload_type=UploadedImageWithMaxSize) ● Filters can be applied to attachments UploadedFileField(filters=[WithThumbnailFilter()]) ● Multiple filters can be applied (rescale image and create thumbnails)
  • 20. Custom Attachments ● Attachment Classes are in charge of storing the actually uploaded file ● They can change the file before it’s uploaded. ● They can add additional data and even behaviours to the file.
  • 21. Filters ● Each attachment can have multiple filters ● They run after upload, so they can add metadata or generate new files but not replace the original one. ● They can store additional metadata with the file, but not behaviours (methods).
  • 23. Web Application Friendly ● Need to serve stored files? Just mount DepotManager.make_middleware around your app and start serving them. ● If files are stored on a backend that supports HTTP, the user will be permanently redirected there by the middleware instead of serving files itself.
  • 24. Made for the Web ● Storage backends can provide public url for any CDN ● File information common in HTTP are provided as properties out of the box ○ content_type ○ last_modified ○ content_length ○ filename
  • 25. Feel free to try it! ● Python 2.6, 2.7, 3.2, 3.3 and 3.4 ● pip install filedepot ● Fully Documented https://depot. readthedocs.org ● Tested with 100% coverage https://travis-ci.org/amol-/depot