55
How to Build Front-End Web Apps that Scale 2014

How to Build Front-End Web Apps that Scale - FutureJS

Embed Size (px)

DESCRIPTION

Developing large apps is difficult. Ensuring that code is consistent, well structured, tested, maintainable and has an architecture that encourages enhancement is essential. When it comes to large server-focused apps, solutions to this problem have been tried and tested. But, with the ongoing dramatic shift of functionality into the browser, how do you achieve this when building Front-End Web Apps? In this talk we’ll cover the signs to watch out for as your HTML5 SPA grows and provide examples of some of the tooling types that can contribute-to - as well as ease - the growing pains. Finally, we’ll demonstrate how tooling can be used to support a set of conventions, practices and principles that enable a productive developer workflow where the first line of code is feature code, features can be developed in isolation, code conflicts are avoided by grouping assets by feature and features are composed into apps. The demonstrations will use the BladeRunnerJS open source developer toolkit, but the concepts are widely applicable.

Citation preview

Page 1: How to Build Front-End Web Apps that Scale - FutureJS

How to Build Front-End Web Apps that Scale

2014

Page 2: How to Build Front-End Web Apps that Scale - FutureJS

Phil @leggetter [email protected]

Caplin Systems !

Page 3: How to Build Front-End Web Apps that Scale - FutureJS

What is a large-scale JavaScript app?

Page 4: How to Build Front-End Web Apps that Scale - FutureJS

–Addy Osmani, Patterns For Large-Scale JavaScript Application Architecture

In my view, large-scale JavaScript apps are non-trivial applications requiring significant

developer effort to maintain, where most heavy lifting of data manipulation and display falls to

the browser.

Page 5: How to Build Front-End Web Apps that Scale - FutureJS

Large CodebaseMore functionality === More code

Page 6: How to Build Front-End Web Apps that Scale - FutureJS

Caplin Trader• SDK:

• ~1,000 JavaScript files

• ~131,000 LoC

• ~131 lines per file

• ~650 test files

• ~95,000 test LoC

• Typical Apps:

• ~425 JavaScript files

• ~50,000 LoC

• ~117 lines per file

• ~200 test files

• ~21,000 test LoC

Page 7: How to Build Front-End Web Apps that Scale - FutureJS

Complexity

Page 8: How to Build Front-End Web Apps that Scale - FutureJS
Page 9: How to Build Front-End Web Apps that Scale - FutureJS
Page 10: How to Build Front-End Web Apps that Scale - FutureJS

Gmail & Caplin Trader• Large Single Page Apps (SPAs)

• Complex functionality

• Complex interactions

• User

• Technology

• Leave open all day

Page 11: How to Build Front-End Web Apps that Scale - FutureJS

Features: Change, Come & Go

Page 12: How to Build Front-End Web Apps that Scale - FutureJS

Feature Progression

Page 13: How to Build Front-End Web Apps that Scale - FutureJS

ContributorsThe Human Factor

Page 14: How to Build Front-End Web Apps that Scale - FutureJS

Who contributes to an app?• Front-end devs

• Back-end devs

• Designers

• QA

• Infrastructure and release engineers

• Technical authors

Page 15: How to Build Front-End Web Apps that Scale - FutureJS

So, how do you ensure an application is maintainable?

1. structure a massive codebase (js, css, html, i18n, images, config etc.)

2. an architecture for complex functionality and interaction (UI and other components)

3. make sure that all contributors can work in harmony

4. promote quality

5. development must be a productive experience

6. ensure all these compliment each other

Page 16: How to Build Front-End Web Apps that Scale - FutureJS

The Solutions

1. Components/Widgets/Modules

2. A Services Layer

3. MV*

4. Efficient Testing

5. Tools to Support Workflow

Page 17: How to Build Front-End Web Apps that Scale - FutureJS

Prove it!

Page 18: How to Build Front-End Web Apps that Scale - FutureJS

Component/Module/Feature/Blade

Page 19: How to Build Front-End Web Apps that Scale - FutureJS

Finding assets is hard

Page 20: How to Build Front-End Web Apps that Scale - FutureJS

/assets /feature-name

Page 21: How to Build Front-End Web Apps that Scale - FutureJS

Long App Reloads

Page 22: How to Build Front-End Web Apps that Scale - FutureJS

Image of app partially workingWho Broken the

App?

Page 23: How to Build Front-End Web Apps that Scale - FutureJS
Page 24: How to Build Front-End Web Apps that Scale - FutureJS
Page 25: How to Build Front-End Web Apps that Scale - FutureJS

Running in isolation ===

Faster reload times

Page 26: How to Build Front-End Web Apps that Scale - FutureJS

Compose Components/Modules

into Apps

Page 27: How to Build Front-End Web Apps that Scale - FutureJS
Page 28: How to Build Front-End Web Apps that Scale - FutureJS

Services

Page 29: How to Build Front-End Web Apps that Scale - FutureJS

What is a service?• Use services to access shared resources

• In-app inter-component messaging

• Persistence Service

• RESTful Service

• Realtime Service

• Services are a Contract/Protocol/Interface

Page 30: How to Build Front-End Web Apps that Scale - FutureJS

Using Services• Use a unique identifier for each service

• Register (code or config). Code example:

!

• Get

http://martinfowler.com/articles/injection.html#ADynamicServiceLocator

Page 31: How to Build Front-End Web Apps that Scale - FutureJS
Page 32: How to Build Front-End Web Apps that Scale - FutureJS
Page 33: How to Build Front-End Web Apps that Scale - FutureJS
Page 34: How to Build Front-End Web Apps that Scale - FutureJS

Why use services?

• Features should not directly communicate

• Easily change implementation

• Implementations can be injected for different scenarios:

• Workbench / Test / App

Page 35: How to Build Front-End Web Apps that Scale - FutureJS

Fake Services

Page 36: How to Build Front-End Web Apps that Scale - FutureJS

Fake/Stub/Mock Services

Page 37: How to Build Front-End Web Apps that Scale - FutureJS

Real Services

Page 38: How to Build Front-End Web Apps that Scale - FutureJS

Efficient Testing (We’ll get to MV*)

Page 39: How to Build Front-End Web Apps that Scale - FutureJS
Page 40: How to Build Front-End Web Apps that Scale - FutureJS

Don’t Touch that DOM

Page 41: How to Build Front-End Web Apps that Scale - FutureJS

MVVM

Page 42: How to Build Front-End Web Apps that Scale - FutureJS

End-to-End Module Testing

• Testing features in isolation

• Change view model and assert against mocked Service

• Inject fake service, make calls and assert View Model

Page 43: How to Build Front-End Web Apps that Scale - FutureJS
Page 44: How to Build Front-End Web Apps that Scale - FutureJS

Need Proof?Our full suite Caplin Trader

testing time went from

>8 Hours

< 30 minutes

Much less for a single feature

Page 45: How to Build Front-End Web Apps that Scale - FutureJS

Tooling & Developer Workflow Focus on Features

Page 46: How to Build Front-End Web Apps that Scale - FutureJS
Page 47: How to Build Front-End Web Apps that Scale - FutureJS

What tooling offers?

Page 48: How to Build Front-End Web Apps that Scale - FutureJS

Automation

• Define workflow & promote consistency

• Scaffolding

• Dev Server

• Builds/Bundling

• Tests

Page 49: How to Build Front-End Web Apps that Scale - FutureJS

Intelligence

Page 50: How to Build Front-End Web Apps that Scale - FutureJS

Compliance

Page 51: How to Build Front-End Web Apps that Scale - FutureJS

Dependency Analysis

Page 52: How to Build Front-End Web Apps that Scale - FutureJS

Knowledge of Runtime Scenarios

• Workbench (dev-mode)

• Test

• App

Page 53: How to Build Front-End Web Apps that Scale - FutureJS

Customization

• Augment workflow

• Identify allowable change to workflow

• Automation commands

• Builds/Bundling

• Test Runner

Page 54: How to Build Front-End Web Apps that Scale - FutureJS

Proven!1. structure a massive codebase - by feature

2. an architecture for complex functionality and interaction - Services & MVVM

3. contributor harmony - separation of concerns; codebase structure, modules/components & architecture

4. promote quality - Services & MVVM === Highly testable

5. productive experience - tooling supports all of this & ensure consistency

6. complimentary - Yes, look at all the cross-over!

Page 55: How to Build Front-End Web Apps that Scale - FutureJS

Phil @leggetter [email protected]

Caplin Systems !

!

!

@BladeRunnerJS bladerunnerjs.org