Firebase introduction 
Kewang
2 
Live DEMO 
https://db.tt/40igKVhc
3 
Agenda 
● Variety of sync mechanisms 
● Firebase
Variety of sync mechanisms 
4
5 
Variety of sync mechanisms 
● Polling 
● Comet 
● Long Polling 
● WebSocket 
● Engine.IO (Socket.IO) 
● Polling & Push
6 
Polling 
send scheduling request
7 
Polling 
client server
8 
Polling 
client server 
T0 
T1 
T2
9 
Polling 
client server 
T0 
T1 
T2 
T4 
T5 
T6
10 
Polling 
client server 
T0 
T1 
T2 
T4 
T5 
T6 
T8 
T9 
T10
11 
Polling 
● Pros 
– Easy to implement 
● Cons 
– No efficiency
12 
Comet 
a never died HTTP request
13 
Comet 
client server
14 
Comet 
client server 
T0 
T1
15 
Comet 
client server 
T0 
T1
16 
Comet 
client server 
T0 
T1 
T3 
T2
17 
Comet 
client server 
T0 
T1 
T3 
T6 
T2 
T5
18 
Comet 
client server 
T0 
T1 
T3 
T6 
T8 
T2 
T5 
T7
19 
Comet 
client server 
T0 
T1 
T3 
T6 
T8 
T12 
T2 
T5 
T7 
T11
20 
Comet 
● Pros 
– Save more network traffic 
● Cons 
– Blocking IO issue 
– Always get server response, can't send another request
21 
Long Polling 
send a long time request repeatedly 
when response received
22 
Long Polling 
client server
23 
Long Polling 
client server 
T0 
T1
24 
Long Polling 
client server 
T0 
T1
25 
Long Polling 
client server 
T0 
T1 
T4 
T3
26 
Long Polling 
client server 
T0 
T1 
T4 
T3 
T5
27 
Long Polling 
client server 
T0 
T1 
T4 
T3 
T5
28 
Long Polling 
client server 
T0 
T1 
T4 
T3 
T5 
T21 
T20
29 
Long Polling 
● Pros 
– Save a little network traffic 
– Can send another request 
● Cons 
– I don't know
30 
WebSocket 
FDX communications channels 
over a single TCP connection
31 
WebSocket 
client server
32 
WebSocket 
client server
33 
WebSocket 
client server 
T0 
T1 
T2
34 
WebSocket 
client server 
T0 
T1 
T2 
T3 
T4 
T5
35 
WebSocket 
client server 
T0 
T1 
T2 
T3 
T4 
T5 
T9 
T10 
T11
36 
WebSocket 
client server 
T0 
T1 
T2 
T3 
T4 
T5 
T17 
T18 
T19 
T9 
T10 
T11
37 
WebSocket 
● Pros 
– Bidirectional communication 
– Save more network traffic 
● Cons 
– Proxy & Firewall issue
38 
Engine.IO 
communication layer for Socket.IO
39 
Engine.IO - Socket.IO history 
0.1~0.6.2 0.6.3~0.6.17 0.7.0~0.9.17 1.0.0~now 
websocket ✓ ✓ ✓ ✓ 
server-events ✓ 
flashsocket ✓ ✓ ✓ 
htmlfile ✓ ✓ 
xhr-multipart ✓ ✓ 
xhr-polling ✓ ✓ ✓ 
jsonp-polling ✓ 
polling ✓
40 
Engine.IO - Overview
41 
Engine.IO - Overview 
● Ensure the most reliable realtime communication
42 
Engine.IO - Overview 
● Ensure the most reliable realtime communication 
● Always establishes a long-polling connection first
43 
Engine.IO - Overview 
● Ensure the most reliable realtime communication 
● Always establishes a long-polling connection first 
– then tries to upgrade to better transports that are 
"tested" on the side
Engine.IO - Upgrade transport seamlessly 
44
Engine.IO - Upgrade transport seamlessly 
45 
● Switches from polling to another transport in 
between polling cycles
Engine.IO - Upgrade transport seamlessly 
46 
● Switches from polling to another transport in 
between polling cycles 
● To ensure no messages are lost, the upgrade packet 
will only be sent once all the buffers of the existing 
transport are flushed and the transport is 
considered paused
47 
Engine.IO 
client server
48 
Engine.IO 
client server 
T0 
T1
49 
Engine.IO 
client server 
T0 
T1
50 
Engine.IO 
client server 
T0 
T1
51 
Engine.IO 
client server 
T0 
T1 
T6 
T5 
T7
52 
Engine.IO 
client server 
T0 
T1 
T11 
T6 
T5 
T7 
T10
53 
Engine.IO 
client server 
T0 
T1 
T11 
T6 
T5 
T7 
T10
54 
Engine.IO 
client server 
T0 
T1 
T5 
T7 
T11 
T6 
T12 
T13 
T14 
T10
55 
Engine.IO 
● Pros 
– Auto-switch different network scenario 
● Cons 
– Use particular protocol at server & client
56 
Polling & Push 
simple sync mechanism
57 
Polling & Push - Push off 
client server
58 
Polling & Push - Push off 
client server 
T0 
T1 
T2
59 
Polling & Push - Push off 
client server 
T0 
T1 
T2 
T4 
T5 
T6
60 
Polling & Push - Push off 
client server 
T0 
T1 
T2 
T4 
T5 
T6 
T8 
T9 
T10
61 
Polling & Push - Push on 
client server SNS
62 
Polling & Push - Push on 
client server 
T0 
T1 
T2 
SNS
63 
Polling & Push - Push on 
client server 
T0 
T1 
T2 
T22 
T23 
T24 
SNS
64 
Polling & Push - Push on 
client server 
T0 
T1 
T2 
T22 
T23 
T24 
SNS 
T30
65 
Polling & Push - Push on 
client server 
T0 
T1 
T2 
T22 
T23 
T24 
T31 
T32 
T33 
SNS 
T30
66 
Polling & Push 
● Pros 
– Easy to implement 
● Cons 
– No (official statement)
67 
Firebase
68 
Firebase 
● Save data in the cloud 
● Realtime Data 
● Easy authentication 
● Bulletproof Security 
● Instant Scalability
69 
Pattern 1 - Client Only
70 
Pattern 1 - Client Only 
● Developing a brand new application 
● Needs minimal integration with legacy systems or 
other third party services 
● App doesn’t have heavy data processing needs or 
complex user authentication requirements
71 
Pattern 2 - Client & Server
72 
Pattern 2 - Client & Server 
● To integrate with third party APIs 
● Advanced authentication requirements 
● Can’t run computationally intensive code on a 
client, or requires code to run on a trusted server
73 
Pattern 3 - Existing App
74 
Pattern 3 - Existing App 
● An existing full-featured app, and aren’t planning a 
rewrite 
● Codebase is large and cannot change 
● Add realtime features without touching the rest of 
app
75 
Live DEMO2
76 
FAQ
77 
FAQ 
● Enterprise solution
78 
FAQ 
● Enterprise solution 
– Custom SLA 
– 24*7 support 
– Dedicated clusters 
– Training
79 
FAQ 
● Enterprise solution 
– Custom SLA 
– 24*7 support 
– Dedicated clusters 
– Training 
● Concurrent connection
80 
FAQ 
● Enterprise solution 
– Custom SLA 
– 24*7 support 
– Dedicated clusters 
– Training 
● Concurrent connection 
– Free plan has 50 max connections, otherwise is 
unlimited
81 
FAQ 
● Enterprise solution 
– Custom SLA 
– 24*7 support 
– Dedicated clusters 
– Training 
● Concurrent connection 
– Free plan has 50 max connections, otherwise is 
unlimited 
● Lock-in
82 
FAQ 
● Enterprise solution 
– Custom SLA 
– 24*7 support 
– Dedicated clusters 
– Training 
● Concurrent connection 
– Free plan has 50 max connections, otherwise is unlimited 
● Lock-in 
– Export data to JSON
83 
References 
● Browser 與 Server 持續同步的作法介紹 
● Comet (programming) 
● Engine.IO: the realtime engine 
● Engine.IO Protocol 
● How Firebase Works 
● Firebase Callbacks - what's the underlying trigger? 
● Firebase under the hood - watching web sockets in 
Chrome Developer Tools
84

Firebase introduction

  • 1.
  • 2.
    2 Live DEMO https://db.tt/40igKVhc
  • 3.
    3 Agenda ●Variety of sync mechanisms ● Firebase
  • 4.
    Variety of syncmechanisms 4
  • 5.
    5 Variety ofsync mechanisms ● Polling ● Comet ● Long Polling ● WebSocket ● Engine.IO (Socket.IO) ● Polling & Push
  • 6.
    6 Polling sendscheduling request
  • 7.
  • 8.
    8 Polling clientserver T0 T1 T2
  • 9.
    9 Polling clientserver T0 T1 T2 T4 T5 T6
  • 10.
    10 Polling clientserver T0 T1 T2 T4 T5 T6 T8 T9 T10
  • 11.
    11 Polling ●Pros – Easy to implement ● Cons – No efficiency
  • 12.
    12 Comet anever died HTTP request
  • 13.
  • 14.
    14 Comet clientserver T0 T1
  • 15.
    15 Comet clientserver T0 T1
  • 16.
    16 Comet clientserver T0 T1 T3 T2
  • 17.
    17 Comet clientserver T0 T1 T3 T6 T2 T5
  • 18.
    18 Comet clientserver T0 T1 T3 T6 T8 T2 T5 T7
  • 19.
    19 Comet clientserver T0 T1 T3 T6 T8 T12 T2 T5 T7 T11
  • 20.
    20 Comet ●Pros – Save more network traffic ● Cons – Blocking IO issue – Always get server response, can't send another request
  • 21.
    21 Long Polling send a long time request repeatedly when response received
  • 22.
    22 Long Polling client server
  • 23.
    23 Long Polling client server T0 T1
  • 24.
    24 Long Polling client server T0 T1
  • 25.
    25 Long Polling client server T0 T1 T4 T3
  • 26.
    26 Long Polling client server T0 T1 T4 T3 T5
  • 27.
    27 Long Polling client server T0 T1 T4 T3 T5
  • 28.
    28 Long Polling client server T0 T1 T4 T3 T5 T21 T20
  • 29.
    29 Long Polling ● Pros – Save a little network traffic – Can send another request ● Cons – I don't know
  • 30.
    30 WebSocket FDXcommunications channels over a single TCP connection
  • 31.
  • 32.
  • 33.
    33 WebSocket clientserver T0 T1 T2
  • 34.
    34 WebSocket clientserver T0 T1 T2 T3 T4 T5
  • 35.
    35 WebSocket clientserver T0 T1 T2 T3 T4 T5 T9 T10 T11
  • 36.
    36 WebSocket clientserver T0 T1 T2 T3 T4 T5 T17 T18 T19 T9 T10 T11
  • 37.
    37 WebSocket ●Pros – Bidirectional communication – Save more network traffic ● Cons – Proxy & Firewall issue
  • 38.
    38 Engine.IO communicationlayer for Socket.IO
  • 39.
    39 Engine.IO -Socket.IO history 0.1~0.6.2 0.6.3~0.6.17 0.7.0~0.9.17 1.0.0~now websocket ✓ ✓ ✓ ✓ server-events ✓ flashsocket ✓ ✓ ✓ htmlfile ✓ ✓ xhr-multipart ✓ ✓ xhr-polling ✓ ✓ ✓ jsonp-polling ✓ polling ✓
  • 40.
  • 41.
    41 Engine.IO -Overview ● Ensure the most reliable realtime communication
  • 42.
    42 Engine.IO -Overview ● Ensure the most reliable realtime communication ● Always establishes a long-polling connection first
  • 43.
    43 Engine.IO -Overview ● Ensure the most reliable realtime communication ● Always establishes a long-polling connection first – then tries to upgrade to better transports that are "tested" on the side
  • 44.
    Engine.IO - Upgradetransport seamlessly 44
  • 45.
    Engine.IO - Upgradetransport seamlessly 45 ● Switches from polling to another transport in between polling cycles
  • 46.
    Engine.IO - Upgradetransport seamlessly 46 ● Switches from polling to another transport in between polling cycles ● To ensure no messages are lost, the upgrade packet will only be sent once all the buffers of the existing transport are flushed and the transport is considered paused
  • 47.
  • 48.
    48 Engine.IO clientserver T0 T1
  • 49.
    49 Engine.IO clientserver T0 T1
  • 50.
    50 Engine.IO clientserver T0 T1
  • 51.
    51 Engine.IO clientserver T0 T1 T6 T5 T7
  • 52.
    52 Engine.IO clientserver T0 T1 T11 T6 T5 T7 T10
  • 53.
    53 Engine.IO clientserver T0 T1 T11 T6 T5 T7 T10
  • 54.
    54 Engine.IO clientserver T0 T1 T5 T7 T11 T6 T12 T13 T14 T10
  • 55.
    55 Engine.IO ●Pros – Auto-switch different network scenario ● Cons – Use particular protocol at server & client
  • 56.
    56 Polling &Push simple sync mechanism
  • 57.
    57 Polling &Push - Push off client server
  • 58.
    58 Polling &Push - Push off client server T0 T1 T2
  • 59.
    59 Polling &Push - Push off client server T0 T1 T2 T4 T5 T6
  • 60.
    60 Polling &Push - Push off client server T0 T1 T2 T4 T5 T6 T8 T9 T10
  • 61.
    61 Polling &Push - Push on client server SNS
  • 62.
    62 Polling &Push - Push on client server T0 T1 T2 SNS
  • 63.
    63 Polling &Push - Push on client server T0 T1 T2 T22 T23 T24 SNS
  • 64.
    64 Polling &Push - Push on client server T0 T1 T2 T22 T23 T24 SNS T30
  • 65.
    65 Polling &Push - Push on client server T0 T1 T2 T22 T23 T24 T31 T32 T33 SNS T30
  • 66.
    66 Polling &Push ● Pros – Easy to implement ● Cons – No (official statement)
  • 67.
  • 68.
    68 Firebase ●Save data in the cloud ● Realtime Data ● Easy authentication ● Bulletproof Security ● Instant Scalability
  • 69.
    69 Pattern 1- Client Only
  • 70.
    70 Pattern 1- Client Only ● Developing a brand new application ● Needs minimal integration with legacy systems or other third party services ● App doesn’t have heavy data processing needs or complex user authentication requirements
  • 71.
    71 Pattern 2- Client & Server
  • 72.
    72 Pattern 2- Client & Server ● To integrate with third party APIs ● Advanced authentication requirements ● Can’t run computationally intensive code on a client, or requires code to run on a trusted server
  • 73.
    73 Pattern 3- Existing App
  • 74.
    74 Pattern 3- Existing App ● An existing full-featured app, and aren’t planning a rewrite ● Codebase is large and cannot change ● Add realtime features without touching the rest of app
  • 75.
  • 76.
  • 77.
    77 FAQ ●Enterprise solution
  • 78.
    78 FAQ ●Enterprise solution – Custom SLA – 24*7 support – Dedicated clusters – Training
  • 79.
    79 FAQ ●Enterprise solution – Custom SLA – 24*7 support – Dedicated clusters – Training ● Concurrent connection
  • 80.
    80 FAQ ●Enterprise solution – Custom SLA – 24*7 support – Dedicated clusters – Training ● Concurrent connection – Free plan has 50 max connections, otherwise is unlimited
  • 81.
    81 FAQ ●Enterprise solution – Custom SLA – 24*7 support – Dedicated clusters – Training ● Concurrent connection – Free plan has 50 max connections, otherwise is unlimited ● Lock-in
  • 82.
    82 FAQ ●Enterprise solution – Custom SLA – 24*7 support – Dedicated clusters – Training ● Concurrent connection – Free plan has 50 max connections, otherwise is unlimited ● Lock-in – Export data to JSON
  • 83.
    83 References ●Browser 與 Server 持續同步的作法介紹 ● Comet (programming) ● Engine.IO: the realtime engine ● Engine.IO Protocol ● How Firebase Works ● Firebase Callbacks - what's the underlying trigger? ● Firebase under the hood - watching web sockets in Chrome Developer Tools
  • 84.