brandfolder - json + postgres

22
Ryan Urabe, CTO [email protected] @rurabe CS Awesomefest September 23, 2013

Upload: brandfolder

Post on 31-May-2015

195 views

Category:

Technology


0 download

DESCRIPTION

A talk by the Brandfolder CTO, Ryan Urabe, about how Brandfolder uses JSON and Postgres to simplify it's back-end system.

TRANSCRIPT

Page 1: Brandfolder - JSON + Postgres

Ryan Urabe, [email protected]

@rurabe

CS AwesomefestSeptember 23, 2013

Page 2: Brandfolder - JSON + Postgres

Tech Stack

Client side

Server side

Page 3: Brandfolder - JSON + Postgres

Tech Stack

JSClient side

Server side

Page 4: Brandfolder - JSON + Postgres

Tech Stack

Client side

Server side

Page 5: Brandfolder - JSON + Postgres

Tech Stack

Client side

Server side

Page 6: Brandfolder - JSON + Postgres

Tech Stack

Client side

Server side

Page 7: Brandfolder - JSON + Postgres

Tech Stack

Client side

Server side

Page 8: Brandfolder - JSON + Postgres

JSON

Client side

Server side

Page 9: Brandfolder - JSON + Postgres

JSON

JSO

N

Client side

Server side

Page 10: Brandfolder - JSON + Postgres

JSON

Client side

Server side

Page 11: Brandfolder - JSON + Postgres

JSON

SQ

L+JS

ON

Client side

Server side

Page 12: Brandfolder - JSON + Postgres

Schema

Brandfolder

Logos Images Documents

People Fonts Colors Videos Press Texts

•name•desc

•name•desc

•name•desc

•name•bio•phone•email•twitter•linkedin

•name•desc•googID•otherID

•name•desc•cmyk•rgb•pnt•hex

•name•desc•url

•name•desc•url

•title•body

Page 13: Brandfolder - JSON + Postgres

Single Table Inheritance

Brandfolder

Assets• type• name• desc

Page 14: Brandfolder - JSON + Postgres

Single Table Inheritance

Brandfolder

Assets• type• name• desc

• phone• email• twitter• linkedin• cmyk

• rgb• pnt• hex• url• googID

• otherID

Page 15: Brandfolder - JSON + Postgres

Single Table Inheritance

Brandfolder

Assets• type• name• desc

• phone• email• twitter• linkedin• facebook

• aboutMe• cmyk• rgb• pnt• hex

• hsla• url• source• googID• fontsID

• adobeID• otherID• etc• etc

Page 16: Brandfolder - JSON + Postgres

Single Table Inheritance + JSON

Brandfolder

Assets• type• name• desc• data =>

JSON

Page 17: Brandfolder - JSON + Postgres

Codeclass Asset < ActiveRecord::Base attr_accessible :name, :description include DataDelegator

# the secret sauce!!!end

class Video < Asset attr_accessible :url data_delegate :only=> [:url]

# moar secrets!!!end

Page 18: Brandfolder - JSON + Postgres

Alternatives

• HSTORE

– Supported by ActiveRecord > 4.0

– Can’t nest

• BATF

– Works with any data store

– Need to serialize

– Can’t manipulate or query in the DB

Page 19: Brandfolder - JSON + Postgres

Extending Postgres JSON

• Index the JSON

• Query records by values stored in the

JSON

Page 20: Brandfolder - JSON + Postgres

More Postgres + JSON

• Postgres can also serialize records

natively, returning a string of valid

JSON.

– Does not require the instantiation of

Ruby objects

– FAST

Page 21: Brandfolder - JSON + Postgres

Even more

• You can install V8 in Postgres and

write custom query functions in

Javascript

– Awesome

–Web developers are already familiar

with it

Page 22: Brandfolder - JSON + Postgres

Ryan Urabe, [email protected]

@rurabe

CS AwesomefestSeptember 23, 2013