Architecture of a Modern Web App

33
© 2013 SpringSource, A division of VMware. All rights reserved Re-distribution allowed with author’s consent. Architecture of a Modern Web App Scott Andrews @scothis [email protected]

description

 

Transcript of Architecture of a Modern Web App

Page 1: Architecture of a Modern Web App

© 2013 SpringSource, A division of VMware. All rights reserved

Re-distribution allowed with author’s consent.

Architecture of a Modern Web App

Scott Andrews

@scothis

[email protected]

Page 2: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.2

About Me

Joined SpringSource in 2008

Wearer of many hats

Drifter• frameworks ⇆ applications

• open source ⇆ commercial

• client ⇆ server

• front-end ⇆ back-end

Teams• Spring Web

• tc Server

• Spring Insight

• Cloud Foundry

• SpringSource JavaScript

Page 3: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.3

Agenda

Where we’ve been

Where we’re going

How we’ll get there

Further resources

Questions

Page 4: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.4

Agenda

Where we’ve been

Where we’re going

How we’ll get there

Further resources

Questions

Page 5: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.5

In the beginning...

Page 6: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.6

In the beginning...

Sites were static HTML Pros:• low computational overhead

• highly cacheable

• highly indexable

Cons:

• hard (easy?) to update

• no personalization

• usually poor UI

Page 7: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.7

Let there be CGI

Page 8: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.8

Let there be CGI

Introduced dynamic generated pages

Pros:• dynamic!

• selectively cacheable

• highly indexable

• personalizable

Cons:

• “high” computational overhead

• hard to create

• usually poor UI

Page 9: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.9

LiveScript JavaScript

http://en.wikipedia.org/wiki/File:Pop-up_ads.jpg

Page 10: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.10

LiveScript JavaScript

Dynamic pages

Lightweight complement to applets

Mostly used for simple scripting• basic form validation

• popup ads

• comet cursor trails

Pros:• enhanced usability, maybe

• reduced trips to the server

Cons:

• abuses annoyed users

• business logic often implemented twice: client and server

http://en.wikipedia.org/wiki/File:Pop-up_ads.jpg

Page 11: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.11

AJAX - Web 2.0

Google Maps sparked Web 2.0

GMail• required JavaScript

Pros:• killer UI

• more responsive apps

Cons:

• difficult to cache

• impossible to index

• required JavaScript

Page 12: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.12

Unobtrusive JavaScript

No JavaScript, no problem

Provide features for user agents that support them• fall back to basic HTML

Pros:• wider compatibility

• just as rich UI

• just as responsive

Cons:

• higher development costs

• requires thoughtful engineering

Page 13: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.13

Client Side Applications

Business logic lives on the client

Resources and permanent state stored on the server

Application and session state stored on client

Pros:• reduce server workloads

• application is highly cacheable

• extremely rich UI

Cons:

• content not indexable

• requires JavaScript

• often requires a ‘modern’ browser

Page 14: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.14

Agenda

Where we’ve been

Where we’re going

How we’ll get there

Further resources

Questions

Page 15: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.15

From server-side app to smart clients and services

Browser-based

HTML Rendering

(progressive enhancement)

HTML HTTP

ApplicationServer

ViewGeneration Controllers

Client

Server

Browser

Service Layer

Channels Repositories RDBMSCRUD

Page 16: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.16

From server-side app to smart clients and services

Client

ServerRDBMSCRUD

HTML5 & JS Engine

ControllersDOM

Client-side model

Service Layer

Channels Repositories

web stg

HTTP &WebSockets

events &notificationsJSON

Browser app orembedded in native

Page 17: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.17

From server-side app to smart clients and services

Client

RDBMSCRUD

HTML5 & JS Engine

ControllersDOM

Client-side model

Service Layer

Channels Repositories

web stg

HTTP &WebSockets

events &notificationsJSON

Service Service Service

Browser app orembedded in native

Server

business / domain services

Page 18: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.18

From server-side app to smart clients and services

Client

RDBMSCRUD

HTML5 & JS Engine

ControllersDOM

Client-side model

Channels Repositories

web stg

HTTP &WebSockets

events &notificationsJSON

Service Service Servicebusiness / domain services

Browser app orembedded in native

Server

Page 19: Architecture of a Modern Web App

platform services,web APIs

Re-distribution allowed with author’s consent.19

From server-side app to smart clients and services

ClientHTML5 & JS Engine

ControllersDOM

Client-side model web stg

HTTP &WebSockets

events &notificationsJSON

Service Service Servicebusiness / domain services

Browser app orembedded in native

Service Service Service

SQL NoSQL otherPaaS

Page 20: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.

DemoApplications as Services

Monty Hall

20

Page 21: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.21

Agenda

Where we’ve been

Where we’re going

How we’ll get there

Further resources

Questions

Page 22: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.22

Client side code as a first class citizen

Apply design patterns• all of your old favorites still apply

• functional and OO patterns

Modularize• decompose applications

• let loaders reassemble

Unit test• several excellent test harnesses

Enforce code quality• JSHint

Page 23: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.

DemoClient side code as a first class citizen

23

Page 24: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.24

Think Messaging

Web Sockets are message based

Web Workers are message based

DOM Events are message based

Web vs Integration is a false dichotomy

Page 25: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.

DemoClient-Server Messaging

25

Page 26: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.26

Simplify Views

Simple templates can render on the client or server• JSP, et al will never render client side

Can the model be cleanly serialized?• anemic domain model has benefits

Avoid imperative logic• lots of conditions may indicate the model is poorly structured

Page 27: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.27

Client vs Server

The definitions of “back-end” and “front-end” are shifting• font-end != client, back-end != server

Embrace both sides

Specialize in client-server integration

Page 28: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.28

Frameworks

New frameworks are emerging• quickly reaching maturity

• watch this space

Frameworks will not solve all your issues• sorry

Page 29: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.29

Agenda

Where we’ve been

Where we’re going

How we’ll get there

Further resources

Questions

Page 30: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.30

IoC + JavaScript

Decompose applications into modules

Assemble modules together with Dependency Injection

Brian Cavalier and John Hann• founders of Cujo.js

Webinar January 31st• signup: http://www.springsource.org/node/3768

• sneak peak: http://www.youtube.com/watch?v=TqX-CqYYwEc

Page 31: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.31

Questions?

Page 32: Architecture of a Modern Web App

Re-distribution allowed with author’s consent.32

Links

Libraries• clicks.js: https://github.com/s2js/clicks

• integration.js: https://github.com/s2js/integration

• rest.js: https://github.com/s2js/rest

• wire.js: https://github.com/cujojs/wire

Scripted Editor: http://scripted-editor.github.com/scripted/

Monty Hall application• front-end: https://github.com/five-eleven/monty-hall-ui

• back-end: https://github.com/acolyer/monty-hall

IoC + JavaScript Webinar: http://www.springsource.org/node/3768

Page 33: Architecture of a Modern Web App

© 2013 SpringSource, A division of VMware. All rights reserved

Re-distribution allowed with author’s consent.

Architecture of a Modern Web App

Scott Andrews

@scothis

[email protected]