117
How do You Build Big Apps? @rjrodger senecajs.org Tuesday 13 August 2013

The Seneca Pattern at EngineYard Distill 2013 Conference

Embed Size (px)

DESCRIPTION

A discussion of the psychological basis for the Seneca message-passing and micro-service pattern.

Citation preview

Page 1: The Seneca Pattern at EngineYard Distill 2013 Conference

How do You Build Big Apps?

@rjrodgersenecajs.org

Tuesday 13 August 2013

Page 2: The Seneca Pattern at EngineYard Distill 2013 Conference

TechnicalDebt

Tuesday 13 August 2013

Page 3: The Seneca Pattern at EngineYard Distill 2013 Conference

"A good plan, violently executed now,is better than a perfect plan next week."

Tuesday 13 August 2013

Page 4: The Seneca Pattern at EngineYard Distill 2013 Conference

You Must take onTechnical Debtor You Will Die

Tuesday 13 August 2013

Page 5: The Seneca Pattern at EngineYard Distill 2013 Conference

Sometimes,it Happens

AnywayTuesday 13 August 2013

Page 6: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 7: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 8: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 9: The Seneca Pattern at EngineYard Distill 2013 Conference

NTSC 1941 Standard:

Black+White onlySignal encodes BrightnessEach Channel gets 6Mhz

Happy Days!

Tuesday 13 August 2013

Page 10: The Seneca Pattern at EngineYard Distill 2013 Conference

Color TelevisionThree Colors: Red, Green, Blue

Each Color needs 3MhzYou only have 6Mhzand you need 9Mhz!

Technical Debt FTW

Tuesday 13 August 2013

Page 11: The Seneca Pattern at EngineYard Distill 2013 Conference

You can't Break theold Black+White TVs

Tuesday 13 August 2013

Page 12: The Seneca Pattern at EngineYard Distill 2013 Conference

We must send the old brightness signal

White Light =30% Red

59% Green11% Blue

Send White, Red and Blue

Tuesday 13 August 2013

Page 13: The Seneca Pattern at EngineYard Distill 2013 Conference

You need to embed the color signals inside

the brightness signal

Tuesday 13 August 2013

Page 14: The Seneca Pattern at EngineYard Distill 2013 Conference

Color TV circuits aremore complicated

than they should be.

Tuesday 13 August 2013

Page 15: The Seneca Pattern at EngineYard Distill 2013 Conference

How do you ReduceTechnical Debt?

Tuesday 13 August 2013

Page 16: The Seneca Pattern at EngineYard Distill 2013 Conference

Longer and more detailed

Specifications!

Tuesday 13 August 2013

Page 17: The Seneca Pattern at EngineYard Distill 2013 Conference

Better LanguagesBetter Mental Models

Tuesday 13 August 2013

Page 18: The Seneca Pattern at EngineYard Distill 2013 Conference

How did theRomans do

Long Division?Tuesday 13 August 2013

Page 19: The Seneca Pattern at EngineYard Distill 2013 Conference

LXXII MMMDCXIIL rem XII

Tuesday 13 August 2013

Page 20: The Seneca Pattern at EngineYard Distill 2013 Conference

How did theRomans doAddition?

Tuesday 13 August 2013

Page 21: The Seneca Pattern at EngineYard Distill 2013 Conference

1. Normalize: IV → IIII2. Concatenate: IIII + XI → IIIIXI3. Sort, descending: IIIIXI → XIIIII4. Reduce: XIIIII → XV

IV + XI = ?

Tuesday 13 August 2013

Page 22: The Seneca Pattern at EngineYard Distill 2013 Conference

How did theRomans do

Subtraction?Tuesday 13 August 2013

Page 23: The Seneca Pattern at EngineYard Distill 2013 Conference

1. Normalize: XXIV → XXIIII2. Eliminate: XXIIII - XV → XIIII - V3. Expand: XIIII - V → VIIIIIIIII - V4. Repeat 2 and 3 until no moves left5. Reduce: IIIIIIIII → IX

XXIV - XV = ?

Tuesday 13 August 2013

Page 24: The Seneca Pattern at EngineYard Distill 2013 Conference

How did theRomans do

Multiplication?Tuesday 13 August 2013

Page 25: The Seneca Pattern at EngineYard Distill 2013 Conference

III → 3VI → 6 → 110

III × VI = ?

3 × 001 × 0 = 03 × 010 × 1 = 63 × 100 × 1 = 12 18

bit shifting

Tuesday 13 August 2013

Page 26: The Seneca Pattern at EngineYard Distill 2013 Conference

How did theRomans doDivision?

Tuesday 13 August 2013

Page 27: The Seneca Pattern at EngineYard Distill 2013 Conference

they didn't

Tuesday 13 August 2013

Page 28: The Seneca Pattern at EngineYard Distill 2013 Conference

Roman Numerals have

Technical DebtTuesday 13 August 2013

Page 29: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 30: The Seneca Pattern at EngineYard Distill 2013 Conference

Positional Number Systems make us

SmarterTuesday 13 August 2013

Page 31: The Seneca Pattern at EngineYard Distill 2013 Conference

Mental Modelsfor Code

Tuesday 13 August 2013

Page 32: The Seneca Pattern at EngineYard Distill 2013 Conference

ProceduralFunctional

Object-OrientedLogic

Tuesday 13 August 2013

Page 33: The Seneca Pattern at EngineYard Distill 2013 Conference

Let's Experiment

Tuesday 13 August 2013

Page 34: The Seneca Pattern at EngineYard Distill 2013 Conference

Stand up.Everybody.

Tuesday 13 August 2013

Page 35: The Seneca Pattern at EngineYard Distill 2013 Conference

Is this a car?

Tuesday 13 August 2013

Page 36: The Seneca Pattern at EngineYard Distill 2013 Conference

YES NOStay standing Sit down

And stay down!

Tuesday 13 August 2013

Page 37: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 38: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 39: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 40: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 41: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 42: The Seneca Pattern at EngineYard Distill 2013 Conference

Tuesday 13 August 2013

Page 43: The Seneca Pattern at EngineYard Distill 2013 Conference

Objects areRoman Numerals

Tuesday 13 August 2013

Page 44: The Seneca Pattern at EngineYard Distill 2013 Conference

Objects break as system complexity

growsTuesday 13 August 2013

Page 45: The Seneca Pattern at EngineYard Distill 2013 Conference

The need for design "patterns" is telling

you somethingTuesday 13 August 2013

Page 46: The Seneca Pattern at EngineYard Distill 2013 Conference

ProceduralFunctional

Object-OrientedLogic

Tuesday 13 August 2013

Page 47: The Seneca Pattern at EngineYard Distill 2013 Conference

Procedural code tends to

SpaghettiTuesday 13 August 2013

Page 48: The Seneca Pattern at EngineYard Distill 2013 Conference

ProceduralFunctional

Object-OrientedLogic

Tuesday 13 August 2013

Page 49: The Seneca Pattern at EngineYard Distill 2013 Conference

Functional and Logic are

More PowerfulTuesday 13 August 2013

Page 50: The Seneca Pattern at EngineYard Distill 2013 Conference

WhatHappened?

Why didn't theyWin?

Tuesday 13 August 2013

Page 51: The Seneca Pattern at EngineYard Distill 2013 Conference

Technical Debt

Tuesday 13 August 2013

Page 52: The Seneca Pattern at EngineYard Distill 2013 Conference

ProceduralFunctional

Object-OrientedLogic

Tuesday 13 August 2013

Page 53: The Seneca Pattern at EngineYard Distill 2013 Conference

What do weNeed?

Tuesday 13 August 2013

Page 54: The Seneca Pattern at EngineYard Distill 2013 Conference

A BetterMental Model

Tuesday 13 August 2013

Page 55: The Seneca Pattern at EngineYard Distill 2013 Conference

Easy to LearnEasy to Scale (humans)Easy to Scale (machines)Easy to ImplementEasy to build a Mental Model

Does not have to achieveVery Large Scale

Tuesday 13 August 2013

Page 56: The Seneca Pattern at EngineYard Distill 2013 Conference

We need Modelsthat Work forHuman Brains

Tuesday 13 August 2013

Page 57: The Seneca Pattern at EngineYard Distill 2013 Conference

Why isRuby on Rails

Popular?Tuesday 13 August 2013

Page 58: The Seneca Pattern at EngineYard Distill 2013 Conference

Opinionated==

Shared Mental ModelTuesday 13 August 2013

Page 59: The Seneca Pattern at EngineYard Distill 2013 Conference

Ruby on RailsModel is an

Accident of HistoryTuesday 13 August 2013

Page 60: The Seneca Pattern at EngineYard Distill 2013 Conference

Let's Design aModel!

Tuesday 13 August 2013

Page 61: The Seneca Pattern at EngineYard Distill 2013 Conference

What does a Programmer do?

Self-contained AlgorithmsProcedural Business LogicFitting it all Together

Tuesday 13 August 2013

Page 62: The Seneca Pattern at EngineYard Distill 2013 Conference

Fitting it all Together is

the Hard PartTuesday 13 August 2013

Page 63: The Seneca Pattern at EngineYard Distill 2013 Conference

What are HumansGood At?

Tuesday 13 August 2013

Page 64: The Seneca Pattern at EngineYard Distill 2013 Conference

If a card has a vowel on one side, it must have an odd number on the other.

Which cards should you turn over to verify that the rule is followed?

Tuesday 13 August 2013

Page 65: The Seneca Pattern at EngineYard Distill 2013 Conference

If you're drinking beer, you must be 21 or over.

Which patrons should you ask for ID?

Tuesday 13 August 2013

Page 66: The Seneca Pattern at EngineYard Distill 2013 Conference

You solved the second version using

Pattern MatchingTuesday 13 August 2013

Page 67: The Seneca Pattern at EngineYard Distill 2013 Conference

Why is Pattern Matching

Such a Win?Tuesday 13 August 2013

Page 68: The Seneca Pattern at EngineYard Distill 2013 Conference

We are Pattern MatchersIt scales for humans and machinesWorks without needing context

Tuesday 13 August 2013

Page 69: The Seneca Pattern at EngineYard Distill 2013 Conference

Why do I Care?

Tuesday 13 August 2013

Page 70: The Seneca Pattern at EngineYard Distill 2013 Conference

We build Minimum Viable Productsfor startups.It's all about technical debt.

Tuesday 13 August 2013

Page 71: The Seneca Pattern at EngineYard Distill 2013 Conference

Lucius Annaeus Seneca

Tuesday 13 August 2013

Page 72: The Seneca Pattern at EngineYard Distill 2013 Conference

The Seneca Strategy

Tuesday 13 August 2013

Page 73: The Seneca Pattern at EngineYard Distill 2013 Conference

EmbraceMicro-Services

Tuesday 13 August 2013

Page 74: The Seneca Pattern at EngineYard Distill 2013 Conference

Lots of Little ProcessesDo one thing, and do it WellCommunicate with Messages

Tuesday 13 August 2013

Page 75: The Seneca Pattern at EngineYard Distill 2013 Conference

Pattern Match onMessages

Tuesday 13 August 2013

Page 76: The Seneca Pattern at EngineYard Distill 2013 Conference

Messages are Asynchronous Send them any way you likeUse JSON as the data model

Tuesday 13 August 2013

Page 77: The Seneca Pattern at EngineYard Distill 2013 Conference

"Send Tweet"Acted on by Tweet Service

Example

{ command:"tweet" author:"@rjrodger" status:"Distill Rocks!"}

Tuesday 13 August 2013

Page 78: The Seneca Pattern at EngineYard Distill 2013 Conference

Tweet ServiceIf I see a message with this property:

Match the Pattern!

command:"tweet"

It's Mine!I don't care how you get it to me.

And I'll ignore anything else.

Tuesday 13 August 2013

Page 79: The Seneca Pattern at EngineYard Distill 2013 Conference

The Tweet Service can be written in

Any LanguageTuesday 13 August 2013

Page 80: The Seneca Pattern at EngineYard Distill 2013 Conference

Keep it SmallDie and restart on Errors

Report your status

Tuesday 13 August 2013

Page 81: The Seneca Pattern at EngineYard Distill 2013 Conference

Level Up ThePattern Matching

Tuesday 13 August 2013

Page 82: The Seneca Pattern at EngineYard Distill 2013 Conference

Patterns map to Actions

Tuesday 13 August 2013

Page 83: The Seneca Pattern at EngineYard Distill 2013 Conference

cmd:drivestart engine, and go!

cmd:drive, type:hoverturn on anti-gravitystart engine and go!

Example

Tuesday 13 August 2013

Page 84: The Seneca Pattern at EngineYard Distill 2013 Conference

Two Rules to make this Unique

1. More properties always wins2. Check properties alphabetically

Tuesday 13 August 2013

Page 85: The Seneca Pattern at EngineYard Distill 2013 Conference

cmd:drive

cmd:drive,type:hover

Mappingcmd: drivetype: wheelspeed: 50

cmd: drivetype: hoverspeed: 100

Tuesday 13 August 2013

Page 86: The Seneca Pattern at EngineYard Distill 2013 Conference

One More Thing

Tuesday 13 August 2013

Page 87: The Seneca Pattern at EngineYard Distill 2013 Conference

Layers

Tuesday 13 August 2013

Page 88: The Seneca Pattern at EngineYard Distill 2013 Conference

When you add a pattern:If the pattern Already Exists,

Keep the Old Action,so you can use it

inside the New Action

Tuesday 13 August 2013

Page 89: The Seneca Pattern at EngineYard Distill 2013 Conference

cmd:drivestart engine, and go!

cmd:drivecall prior actionset speed to speed

Example

Tuesday 13 August 2013

Page 90: The Seneca Pattern at EngineYard Distill 2013 Conference

Implementation

senecajs.org

Tuesday 13 August 2013

Page 91: The Seneca Pattern at EngineYard Distill 2013 Conference

Let's build stuff!

Tuesday 13 August 2013

Page 92: The Seneca Pattern at EngineYard Distill 2013 Conference

Blog Data Layer

Platform-as-a-Service

Tuesday 13 August 2013

Page 93: The Seneca Pattern at EngineYard Distill 2013 Conference

the actions are

Blog

cmd:draft, post:contentcmd:publish, post:idcmd:redact, post:idcmd:homepagecmd:comment, post:id, comment:comment

Tuesday 13 August 2013

Page 94: The Seneca Pattern at EngineYard Distill 2013 Conference

action, not abstractioneasy to learn

easy to modifyeasy to maintainself-documenting

Win

Tuesday 13 August 2013

Page 95: The Seneca Pattern at EngineYard Distill 2013 Conference

the actions are

Data Layer

cmd:save, name:entitycmd:load, name:entitycmd:list, name:entitycmd:remove, name:entity

Tuesday 13 August 2013

Page 96: The Seneca Pattern at EngineYard Distill 2013 Conference

save some data

cmd: save, name: product,data: { name: Apple, price: 1.99 }

Tuesday 13 August 2013

Page 97: The Seneca Pattern at EngineYard Distill 2013 Conference

load some data

cmd: load, name: product,query: { name:Apple }

Tuesday 13 August 2013

Page 98: The Seneca Pattern at EngineYard Distill 2013 Conference

implement the actions

cmd:saveinsert into table name values data

cmd:loadselect * from name where query

Tuesday 13 August 2013

Page 99: The Seneca Pattern at EngineYard Distill 2013 Conference

add caching

cmd:savecall prior actionwrite into cache data

cmd:loadread data from cacheif found, return data, else call prior action

Tuesday 13 August 2013

Page 100: The Seneca Pattern at EngineYard Distill 2013 Conference

layers

cmd:savecall prior actionwrite into cache data

cmd:loadread data from cacheif found, return data, else call prior action

insert into table name values data

select * from name where query

Tuesday 13 August 2013

Page 101: The Seneca Pattern at EngineYard Distill 2013 Conference

more data layers

validationpermissionsthrottling

custom logicmultiple databases

...

Tuesday 13 August 2013

Page 102: The Seneca Pattern at EngineYard Distill 2013 Conference

multiple databases

cmd:save, name:sessionsave data to redis

cmd:saveinsert into table name values data

when entity is a session:

all other entities:

Tuesday 13 August 2013

Page 103: The Seneca Pattern at EngineYard Distill 2013 Conference

fine-grained controleasy to extend

easy to customizeeasy to debug - there's no magic

Win

Tuesday 13 August 2013

Page 104: The Seneca Pattern at EngineYard Distill 2013 Conference

Micro-Services

deployerdispatchercontroller

Platform-as-a-Service

Tuesday 13 August 2013

Page 105: The Seneca Pattern at EngineYard Distill 2013 Conference

deployer

controller

dispatcher

app appapp

requestsstartstop

install

route

dashboard

Tuesday 13 August 2013

Page 106: The Seneca Pattern at EngineYard Distill 2013 Conference

controller actionsdash:install, app:detailssubmit cmd:install, app:details to message bus (deployer picks up)

dash:start, app:idsubmit cmd:start, app:id to message bus (dispatcher picks up)

dash:stop, app:idsubmit cmd:stop, app:id to message bus (dispatcher picks up)

Tuesday 13 August 2013

Page 107: The Seneca Pattern at EngineYard Distill 2013 Conference

deployer actionscmd:install, app:details

download app code to serverget route from app detailssubmit cmd:route, route:path, server:server to message bus (dispatcher picks up)

Tuesday 13 August 2013

Page 108: The Seneca Pattern at EngineYard Distill 2013 Conference

dispatcher actionscmd:routeadd route and server to local routing table

cmd:start, app:idstart routing requests to app

cmd:stop, app:idstop routing requests to app

Tuesday 13 August 2013

Page 109: The Seneca Pattern at EngineYard Distill 2013 Conference

controller, dispatcher, deployer are all in one app

install apps to localhostfocus on what, not how

Prototype

Tuesday 13 August 2013

Page 110: The Seneca Pattern at EngineYard Distill 2013 Conference

controller, dispatcher, deployer are separate processes

communicate via direct HTTPapps live on VMs

but ... no design changes!

Minimum ViableProduct

Tuesday 13 August 2013

Page 111: The Seneca Pattern at EngineYard Distill 2013 Conference

controller, dispatcher, deployer are many processes

communicate via a message busapps live anywhere

but ... no design changes!

Scale It

Tuesday 13 August 2013

Page 112: The Seneca Pattern at EngineYard Distill 2013 Conference

build now, scale later!easy refactoring

language independenceeasily observe and manage

Win

Tuesday 13 August 2013

Page 113: The Seneca Pattern at EngineYard Distill 2013 Conference

How do You Build Big Apps?

Tuesday 13 August 2013

Page 114: The Seneca Pattern at EngineYard Distill 2013 Conference

Design for ManyLanguages

Tuesday 13 August 2013

Page 115: The Seneca Pattern at EngineYard Distill 2013 Conference

Design forScale

(human + machine)Tuesday 13 August 2013

Page 116: The Seneca Pattern at EngineYard Distill 2013 Conference

Design forHuman Brains

Tuesday 13 August 2013

Page 117: The Seneca Pattern at EngineYard Distill 2013 Conference

Thank You!@rjrodger

senecajs.org

Tuesday 13 August 2013