thin client spas? stream ui using web standards (codenight)

27
Thin client SPAs ? Stream UI using web standards MARCIN WARPECHOWSKI, STARCOUNTER CODENIGHT STOCKHOLM, 2016-06-09

Upload: starcounter

Post on 18-Jan-2017

173 views

Category:

Engineering


3 download

TRANSCRIPT

Page 1: Thin client SPAs? Stream UI using web standards (CodeNight)

Thin client SPAs? Stream UI using web standards

MARC IN WARPECHOW SK I , S TARCOUNTER

CODEN IGHT S T OCKHOLM, 2016 -06 -09

Page 2: Thin client SPAs? Stream UI using web standards (CodeNight)

Agenda- discuss fat vs thin client architectural styles of web apps

- present a thin client pattern and library called “PuppetJs”

- show some code

- questions all the time

github.com/puppetjs/puppetjscodenight.mysampleapp.com

Page 3: Thin client SPAs? Stream UI using web standards (CodeNight)

Fat client SPAs

S TATELESS S TATE #2S TATE #1

SERVER APP CL I ENT APPRES T INTERFACE JSON RES T

C L I ENT

Page 4: Thin client SPAs? Stream UI using web standards (CodeNight)

Typical problems in REST and ROA

- Long-running transactions. I want to work in isolation until I am ready to commit or roll back my changes.

- Data redundancy. I don’t want to send or get more information than needed.

- Cache invalidation. I want to work on current state.

Page 5: Thin client SPAs? Stream UI using web standards (CodeNight)

Problems of fat client- heavy code

- duplicate logic

- increased complexity

- validation on both ends

- glue code

Page 6: Thin client SPAs? Stream UI using web standards (CodeNight)

Thin client should be among the considered solutions

nyctaxi.herokuapp.com

Page 7: Thin client SPAs? Stream UI using web standards (CodeNight)

Pattern for data synchronization.

Uses JSON and JSON-Patch over HTTP and WebSocket.

PuppetJs

Page 8: Thin client SPAs? Stream UI using web standards (CodeNight)

Standards

PuppetJsPattern for data synchronization.

Uses JSON and JSON-Patch over HTTP and WebSocket.

Page 9: Thin client SPAs? Stream UI using web standards (CodeNight)

S T A T E

SERVER APP W I TH V I EW -MODEL JSON V IEW

PuppetJs binds server-side view-models to HTML

Page 10: Thin client SPAs? Stream UI using web standards (CodeNight)

Puppet flow

Page 11: Thin client SPAs? Stream UI using web standards (CodeNight)

Demo time

Page 12: Thin client SPAs? Stream UI using web standards (CodeNight)

JSON is low-res- JSON has just 6 types of value:

- string

- number

- boolean

- null

- object

- array

PR IM I T I VE

COMPOS I TE

Page 13: Thin client SPAs? Stream UI using web standards (CodeNight)

What UI can you represent with JSON?

- text labels and inputs - URLs - Markdown - HTML

- amounts - buttons - geographic coordinates

- checkboxes - toggle buttons - disabled inputs - conditional displaying of things

S TR ING

NUMBER

BOOLEAN

Page 14: Thin client SPAs? Stream UI using web standards (CodeNight)

What UI can you represent with JSON?

- nested views - namespaces

- lists of values - lists of views

OBJECT

ARRAY

Page 15: Thin client SPAs? Stream UI using web standards (CodeNight)

Benefits to productivity- no client side app, no glue code between apps

- works great with JavaScript and Web Components

- composable nested views

Page 16: Thin client SPAs? Stream UI using web standards (CodeNight)

Benefits to performance and UX

- morphing views

- real-time view of the data

- client patches mitigate network latency

Page 17: Thin client SPAs? Stream UI using web standards (CodeNight)

Benefits to integrity- security

- server is the single source of truth

Page 18: Thin client SPAs? Stream UI using web standards (CodeNight)

Challenges for thin client- connection

- latency

- going out of sync

Page 19: Thin client SPAs? Stream UI using web standards (CodeNight)

Connection: always ON- already true for POS, e-commerce, social media, etc

- already true for remote desktop

- solution: have a server on premise, replicate the DB to a master server

Page 20: Thin client SPAs? Stream UI using web standards (CodeNight)

Sthlm-Frankfurt-Sthlm in 42 msMeaning: 23 roundtrips per second

Page 21: Thin client SPAs? Stream UI using web standards (CodeNight)

In 200 ms to NY and backMeaning: 5 roundtrips per second

Page 22: Thin client SPAs? Stream UI using web standards (CodeNight)

Latency mitigation- horizontal partitioning “sharding” - (moving ownership of the

rows)

- replication

Page 23: Thin client SPAs? Stream UI using web standards (CodeNight)

Going out of sync?• web reality: the client and the server are doing concurrent

changes asynchronously (most of the time out-of-sync)

• goal: apply patches correctly without freezing UI or disallowing server push

• solution: Operational Transformation - algorithm that transforms any remote operation over operations that were generated locally

Page 24: Thin client SPAs? Stream UI using web standards (CodeNight)

Without Operational Transformation

CL I ENT SERVER

“ABCDE” “ABCDE”

“ABCE” “ACDE”

“ACD”“ACE”

C = Del 4 S = Del 2

S = Del 2 C = Del 4

T IME

Page 25: Thin client SPAs? Stream UI using web standards (CodeNight)

With Operational Transformation

CL I ENT SERVER

T IME

“ABCDE” “ABCDE”

“ABCE” “ACDE”

“ACD”“ACE”

C = Del 4 S = Del 2

S’ = Del 2 C’ = Del 3

Page 26: Thin client SPAs? Stream UI using web standards (CodeNight)

Puppet implementationsJavaScript: github.com/puppetjs/puppetjs

Web Components: github.com/PuppetJs/puppet-polymer-client

C#: github.com/starcounter/starcounter

Sample apps:Hello World: github.com/warpech/HelloWorldKitchenSink: github.com/StarcounterSamples/KitchenSink

Page 27: Thin client SPAs? Stream UI using web standards (CodeNight)

Thanks! More info on

.io

Twitter: @starcounterdb, @warpech