Flask NYC 09262013

19
FLASK! 18 months in @ happify FLASK NYC 2013 Andy Parsons @andyparsons

description

Presentation at the Flask NYC Meetup, Sept 2013

Transcript of Flask NYC 09262013

Page 1: Flask NYC 09262013

FLASK! 18 months in @ happify

FLASK NYC 2013Andy Parsons @andyparsons

Page 2: Flask NYC 09262013

This talk

FLASK NYC 2013

E x p e r i e n c e a n d L e s s o n s

F l a s k@

H a p p i f y

A n 1 8 - m o n t h - o l da c t i v e F l a s k

c o d e b a s e

H o w I g o t t o F l a s k

Flask has become a VIBRANT, ACTIVE toolkit for HTTP servers.

But there aren’t a lot of large examples from which to learn. LET’S CHANGE THAT.

Page 3: Flask NYC 09262013

Me. • startup junkie. masochist.• co-founder/CTO Happify• previously CTO Outside.in, bookish, ...• MENTOR @ seedcamp, techpeaks, 500 Startups• pragmatist • love choosing tools, Learning, making them better

Page 4: Flask NYC 09262013

not Me.

• Framework zealot• django expert (no comparisons)• IDEALIST

Page 5: Flask NYC 09262013

what is a “microframework?”• just the essentials, nothing more• extensibility through plugins• readable source• minimal magic• easy to build a toy/demo• lack of patterns for larger projects

Page 6: Flask NYC 09262013

FLASK NYC 2013

PROJECT LINES OF CODE COMPLEXITY

Backbone.js < 1000 LOW

Flask (not Werkzeug) ~2000 (?) LOW

Redis 100,000 MEDIUM

Django 170,000 MEDIUM

MongoDB 500,000 HIGH

PostgreSQL > 1,000,000 HIGH!

complexity spectrum

* STATS FROM OHLOH (http://www.ohloh.net/) and http://www.andreas-dewes.de/code_is_beautiful/

Page 7: Flask NYC 09262013

‣ java/spring/.NET‣ a FEW rails-based startups (sinatra mixed in)‣ scala services (scalatra, play)‣ Python a natural fit for happify (data analysis, machine learning, nlp)‣ flask selected as toolkit

my journey to flask

Page 8: Flask NYC 09262013

A Sampling of NYC Python

A Startup Junkie's Journey to Python via Java, Ruby and Scala Andy Parsons@andyparsons

My Startups and Their Stacks What Are We Building? And in general...

Happiness Speed Magic Readability

BUSINESS WEB API SERVICES DATABASES TEAM SIZE

Pro Photo ASP.NET C#, Perl SQL Server 12

Hyperlocal Content

(Geolocation)

RoR Sinatra ScalaPostgreSQL, MongoDB

10

Ereading and Book

Recommender

RoR Scalatra Scala/Java MongoDB 8

Life Gaming FlaskPython/Gevent

PythonPostgreSQL, MongoDB

3

Building Happify: Comparing Language Options

SPEED CONCURRENCY TOOLING PACKAGING / DEPENDENCIES

DEPLOYMENT TESTING FRAMEWORKS / LIBS

RUBY

SCALA

PYTHON

Fast enough Achieved through Process.forkHealthy, lots of

choiceGems Capistrano Mature

Growing collection of libs, but weak in

NLP

Fast! Real concurrency, AkkaStill early. IDE’s

weak.Complex. JARs, SBT, Ivy,

Maven.? Maturing

Early for native scala libraries, rely

on Java interop

Fast enoughAchieved through multiprocessing

Healthy, lots of choice

Eggs Fabric MatureMassive collection

of libraries

READABILITY HAPPINESS / PRODUCTIVITY

COMMUNITY / ACTIVITY

PROPENSITY FOR MAGIC

MATURITY / STABILITY

HIRING

RUBY

SCALA

PYTHON

OK. Emphasis metaprogramming can

present challenges.High Huge and active

Metaprogramming is sometimes abused. RoR is too magical and many imitated its philosophy

Stable, but much catchup remaining for gems to support 1.9

Tough. Medium learning curve, hard to find

seasoned devs

Concise, expressive but NOT simple.

Highly variable! Small and activeToo many ways to accomplish

things. Scala “implicits” encourage magic

Language spec changing, breakages still occurring in dot

releases

Very difficult. Steep learning

curve

Highly readable High Big and active Explicit better than implicitMost mature here.

But the 2.x/3.x break is bad.

OK. Shallow learning curve.

FLAME BAIT

BASICS

Scala Ruby Python

23

18

8

How do they “Stack” Up?

Happify is an angel-funded consumer destination “life game.”

HTML5, Mobile, and Facebook front ends.

Currently in stealth mode.

Score is based on:

Green = 2Yellow = 1Red = 0

Python36%

Ruby60%

Scala4%

Github Project Relative %

Gratuitous Perf Charts!

* from: http://shootout.alioth.debian.org

pycon 2012poster

Page 9: Flask NYC 09262013

what is happify?‣ science of happiness‣ positive psych trainer‣ consumer subscription business‣ launched in beta after 9 months‣ ~100K users‣ imminent public launch

FLASK NYC 2013

Page 10: Flask NYC 09262013

happify stack abbreviated biography• FEbruary 2012: james dennis @j2labs for coffee• march 2012: started coding poc (jinja templates only)• june 2012: alpha poc launched• september 2012: first real design/ux work• october 2012: backbone/coffeescript introduced• december 2013: redis added, closed beta launched• march 2013: ES added, open beta launch• june 2013: commerce, new feature set, scale up to 100K users• august 2013: ”final” design, refactoring for public launch• now: frontend and backend performance, press

Page 11: Flask NYC 09262013

what is large?

Page 12: Flask NYC 09262013

what is large?

• 80 views• 200 templates• 60 backbone views• 50 models• 200 tests (need more!)

Page 13: Flask NYC 09262013

‣ backbone.js‣ coffeescript‣ haml‣ less css‣ flask‣ flask-admin‣ sqlalchemy‣ postgres

The happify stack‣ redis ‣ Elastic search‣ NGINX‣ celery‣ gunicorn‣ aws ec2/s3‣ nose‣ fabric

Page 14: Flask NYC 09262013

‣ api for mobile‣ api for backbone‣ backbone app bootstrapping‣ template rendering‣ administration ui‣ aggregates data from postgres, redis, elasticsearch‣ serializes context-specific object graphs

the role of flask - data switch

Page 15: Flask NYC 09262013

‣ project layout‣ config‣ routing setup‣ db connection management‣ serialization: shallow and deep‣ FAB automation

code

Page 16: Flask NYC 09262013

‣ better config (multiple environments, config heirarchy)‣ authentication‣ assets pipeline‣ model validation and serialization layer (waffling)

batteries i wish were included

batteries i could do without‣ trailing slash redirects (but easy to control)

Page 17: Flask NYC 09262013

python 3! well, almost kinda

• flask/werkzeug support completed• many extensions not yet• fabric, boto, sentry ...• too bad- unicode is a mess without it• Handy: http://python3wos.appspot.com/

Page 18: Flask NYC 09262013

‣ flask is an excellent choice for apps like ours‣ know what you are getting and what you aren’t, make no assumptions‣ prepare to refactor relentlessly ‣ don’t worry that there’s no single way to do it!

conclusions

Page 19: Flask NYC 09262013

contact me:

andy [email protected]@andyparsons

thank you!