architectures for scaling ajax

43
Architectures for Scaling AJAX tools, strategies, tips and tricks Wolfram Kriesing, uxebu [email protected]

Upload: wolframkriesing

Post on 30-Nov-2014

2.710 views

Category:

Technology


6 download

DESCRIPTION

Those are the slides for the talk I gave at the Ajax in Action 2008.

TRANSCRIPT

Page 1: Architectures For Scaling Ajax

Architectures for Scaling AJAX

tools, strategies, tips and tricks

Wolfram Kriesing, [email protected]

Page 2: Architectures For Scaling Ajax

Why client scaling?

• ~10% HTML

• ~90% JavaScript, CSS, media, ...

• UX

Page 3: Architectures For Scaling Ajax

DB traffic ajax

Scaling what?

Page 4: Architectures For Scaling Ajax

Strategies

Tools

Real world

Page 5: Architectures For Scaling Ajax

Strategies

data legacy GUI

features

user

widgets

Page 6: Architectures For Scaling Ajax

I already got an app!

Page 7: Architectures For Scaling Ajax

But I want it Web2.0-ish!

Page 8: Architectures For Scaling Ajax

AJAXify it!

Page 9: Architectures For Scaling Ajax

Enhance it

Page 10: Architectures For Scaling Ajax

Site Loading

Page 11: Architectures For Scaling Ajax

• mostly pre Web 2.0 site

• fresh it up - widgets

• dynamic content

• minimize site height+number - tabs

• better UX

Progressive Enhancement

Page 12: Architectures For Scaling Ajax

• upgrade server code

• stable

• legacy

• unmaintained

• easier: update JS

Progressive EnhancementThe Problem

Page 13: Architectures For Scaling Ajax

• interfaces - url mapper

• url to action/view method

• easy editing

• clean interface

• new namespace - /api/...

Progressive EnhancementThe solution!

Page 14: Architectures For Scaling Ajax

Progressive Enhancement

Page 15: Architectures For Scaling Ajax

Chunks, tabs, ...

Page 16: Architectures For Scaling Ajax

• sugar

• clean start

• organic growth

GUI driven

Page 17: Architectures For Scaling Ajax

• fix data

• adapt server structure

• map UI to data

• UI is data centric

• widgets

Back-end driven

Page 18: Architectures For Scaling Ajax

Strategies

Tools

Real world

Page 19: Architectures For Scaling Ajax

Toolspub sub

cometd

templates

ORM

build

CDN

compressor

memcached

inline data

URLsREST

structure

javascript

triggers

Page 20: Architectures For Scaling Ajax

ORMcartperms

user

items info

stats

item

ads

Page 21: Architectures For Scaling Ajax

ORM

✓maps perfectly to chunks

✓simpler queries

✓more focused

✓object centric

- rather GUI driven

Page 22: Architectures For Scaling Ajax

Triggers

• for simple stats!

• for simple stats!!!

• for simple stats!!!!!!

• support laziness

• easy to refactor later

Page 23: Architectures For Scaling Ajax

Triggersclass Tag(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=50, unique=True) num_uses = models.PositiveIntegerField(default=1)

CREATE TRIGGER au_tag AFTER UPDATE ON tag FOR EACH ROW CALL update_tag_num_uses(NEW.tag_id);

CREATE TRIGGER ai_tag AFTER INSERT ON tag FOR EACH ROW CALL update_tag_num_uses(NEW.tag_id);

CREATE TRIGGER ad_tag AFTER DELETE ON tag FOR EACH ROW CALL update_tag_num_uses(OLD.tag_id);

Page 24: Architectures For Scaling Ajax

Too much DB load!

Page 25: Architectures For Scaling Ajax

memcached

more requeststiny queries

common datastatus

statistics

x x

Page 26: Architectures For Scaling Ajax

Nice and what about the GUI?

Page 27: Architectures For Scaling Ajax

✓loose coupling

✓forces an API

✓as detailed as you like

✓workers enabled

- data passing

Publish/Subscribe

Page 28: Architectures For Scaling Ajax

Publish/Subscribecart/updated

friend/online

window/resizeajax/data

Page 29: Architectures For Scaling Ajax

✓pure client rendering

✓seperation of concerns

✓data only requests

- URLs

- render on client

Client-side Templates

Page 30: Architectures For Scaling Ajax

Client-side Templates

templates

JSON

Page 31: Architectures For Scaling Ajax

cometd

• responsive

• no pull

• different programming model

• pubblish/subscribe

Page 32: Architectures For Scaling Ajax

Defer

• spread the load

• run when needed

Page 33: Architectures For Scaling Ajax

pub/sub

http:// •URL Mapping•API

•memcached•triggers

•templates•JSON

•loose couple•flexibility

•ORM

Page 34: Architectures For Scaling Ajax

✓pub sub

cometd

✓templates

✓ORM

build

CDN

compressor

✓memcached

inline data

✓URLs✓REST

Tools

structure

javascript

✓triggers

Page 35: Architectures For Scaling Ajax

Request

Webserver

Page 36: Architectures For Scaling Ajax

PHP, Python, Java, ... DB

Page 37: Architectures For Scaling Ajax

Request

Webserver

Response

optimize

Page 38: Architectures For Scaling Ajax

PHP, Python, Java, ... DB

optimize

Page 39: Architectures For Scaling Ajax

Request

Webserver

Response

optimize

Page 40: Architectures For Scaling Ajax

• loading order

• inline data

• add on load

• lazy loading

• optimize caching effect

• use the network effect

optimize

Page 41: Architectures For Scaling Ajax

Recap

Page 42: Architectures For Scaling Ajax

Scaling

ServerDB

ORMURLs

cache

loading

loading

code packaging

structureJS

media

chunksJSONXHR

HTML#requests

JSCSS

pub/subtemplates

render time

orderheaders

CDN