188
How to build a scalable SNS via Polling & Push Kewang 三竹資訊

How to build a scalable SNS via Polling & Push

Embed Size (px)

DESCRIPTION

Agenda ● Variety of sync mechanisms ● Polling & Push ● RESTful API Design ● API Blueprint

Citation preview

Page 1: How to build a scalable SNS via Polling & Push

How to build a scalable SNS via Polling & Push

Kewang

三竹資訊

Page 2: How to build a scalable SNS via Polling & Push

2

Who I am

● 王慕羣● Java / Node.js / AngularJS● SQL-like / HBase

● Mentor: NIU CSIE

GitHub: kewangtw

Google Play: kewang

Facebook: kewangtw

Linkedin: kewangtw

Slideshare: kewang

Mail: [email protected]

Page 3: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊

Page 4: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊

大家都唸 Mitake

Page 5: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊

大家都唸 Mitake ,但我們公司都唸 Mitake

Page 6: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊

Mitake 不唸作 MiTAC 啊!!!

Page 7: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊

Page 8: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台

Page 9: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:

Page 10: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:

Page 11: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:不計其數

Page 12: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:不計其數● 行動銀行:

Page 13: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:不計其數● 行動銀行:臺銀、土銀、富邦、台新、聯邦、臺企銀、遠銀、華南、澳盛、郵局、合庫、渣打 ...等 18 家

Page 14: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:不計其數● 行動銀行:臺銀、土銀、富邦、台新、聯邦、臺企銀、遠銀、華南、澳盛、郵局、合庫、渣打 ...等 18 家● 產壽險:

Page 15: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:不計其數● 行動銀行:臺銀、土銀、富邦、台新、聯邦、臺企銀、遠銀、華南、澳盛、郵局、合庫、渣打 ...等 18 家● 產壽險:全球、明台、新光、新安東京、富邦 ...等

Page 16: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:不計其數● 行動銀行:臺銀、土銀、富邦、台新、聯邦、臺企銀、遠銀、華南、澳盛、郵局、合庫、渣打 ... 等

18 家● 產壽險:全球、明台、新光、新安東京、富邦 ... 等● 其他:

Page 17: How to build a scalable SNS via Polling & Push

Who Mitake is

三竹資訊● 簡訊平台● 行動下單:不計其數● 行動銀行:臺銀、土銀、富邦、台新、聯邦、臺企銀、遠銀、華南、澳盛、郵局、合庫、渣打 ... 等 18家● 產壽險:全球、明台、新光、新安東京、富邦 ... 等● 其他: udn 買東西、手機逛週年慶、財政園地、證交所、綜所稅申報 ... 等

Page 18: How to build a scalable SNS via Polling & Push

18

System Architecture

Page 19: How to build a scalable SNS via Polling & Push

19

System Architecture

Page 20: How to build a scalable SNS via Polling & Push

20

System Architecture (Backend)

Page 21: How to build a scalable SNS via Polling & Push

21

System Architecture (Backend)

HadoopCon 2014

Page 22: How to build a scalable SNS via Polling & Push

22

System Architecture (Frontend)

Page 23: How to build a scalable SNS via Polling & Push

23

Agenda

● Variety of sync mechanisms● Polling & Push● RESTful API Design● API Blueprint

Page 24: How to build a scalable SNS via Polling & Push

24

Variety of sync mechanisms

Page 25: How to build a scalable SNS via Polling & Push

25

Variety of sync mechanisms

● Polling● Comet● Long Polling● WebSocket● Engine.IO (Socket.IO)

Page 26: How to build a scalable SNS via Polling & Push

26

Pollingsend scheduling request

Page 27: How to build a scalable SNS via Polling & Push

27

Polling

client server

Page 28: How to build a scalable SNS via Polling & Push

28

Polling

client server

T0T1

T2

Page 29: How to build a scalable SNS via Polling & Push

29

Polling

client server

T0T1

T2

T4T5

T6

Page 30: How to build a scalable SNS via Polling & Push

30

Polling

client server

T0T1

T2

T4T5

T6

T8T9

T10

Page 31: How to build a scalable SNS via Polling & Push

31

Polling

● Pros– Easy to implement

● Cons– No efficiency

Page 32: How to build a scalable SNS via Polling & Push

32

Cometa never died HTTP request

Page 33: How to build a scalable SNS via Polling & Push

33

Comet

client server

Page 34: How to build a scalable SNS via Polling & Push

34

Comet

client server

T0T1

Page 35: How to build a scalable SNS via Polling & Push

35

Comet

client server

T0T1

Page 36: How to build a scalable SNS via Polling & Push

36

Comet

client server

T0T1

T3T2

Page 37: How to build a scalable SNS via Polling & Push

37

Comet

client server

T0T1

T3

T6

T2

T5

Page 38: How to build a scalable SNS via Polling & Push

38

Comet

client server

T0T1

T3

T6T8

T2

T5T7

Page 39: How to build a scalable SNS via Polling & Push

39

Comet

client server

T0T1

T3

T6T8

T12

T2

T5T7

T11

Page 40: How to build a scalable SNS via Polling & Push

40

Comet

● Pros– Save more network traffic

● Cons– Blocking IO issue– Always get server response, can't send another request

Page 41: How to build a scalable SNS via Polling & Push

41

Long Pollingsend a long time request repeatedly

when response received

Page 42: How to build a scalable SNS via Polling & Push

42

Long Polling

client server

Page 43: How to build a scalable SNS via Polling & Push

43

Long Polling

client server

T0T1

Page 44: How to build a scalable SNS via Polling & Push

44

Long Polling

client server

T0T1

Page 45: How to build a scalable SNS via Polling & Push

45

Long Polling

client server

T0T1

T4

T3

Page 46: How to build a scalable SNS via Polling & Push

46

Long Polling

client server

T0T1

T4

T3

T5

Page 47: How to build a scalable SNS via Polling & Push

47

Long Polling

client server

T0T1

T4

T3

T5

Page 48: How to build a scalable SNS via Polling & Push

48

Long Polling

client server

T0T1

T4

T3

T5

T21T20

Page 49: How to build a scalable SNS via Polling & Push

49

Long Polling

● Pros– Save a little network traffic– Can send another request

● Cons– I don't know

Page 50: How to build a scalable SNS via Polling & Push

50

WebSocketFDX communications channels over a single TCP connection

Page 51: How to build a scalable SNS via Polling & Push

51

WebSocket

client server

Page 52: How to build a scalable SNS via Polling & Push

52

WebSocket

client server

Page 53: How to build a scalable SNS via Polling & Push

53

WebSocket

client server

T0T1

T2

Page 54: How to build a scalable SNS via Polling & Push

54

WebSocket

client server

T0T1

T2

T3T4

T5

Page 55: How to build a scalable SNS via Polling & Push

55

WebSocket

client server

T0T1

T2

T3T4

T5T9

T10T11

Page 56: How to build a scalable SNS via Polling & Push

56

WebSocket

client server

T0T1

T2

T3T4

T5

T17T18

T19

T9T10

T11

Page 57: How to build a scalable SNS via Polling & Push

57

WebSocket

● Pros– Bidirectional communication– Save more network traffic

● Cons– Proxy & Firewall issue

Page 58: How to build a scalable SNS via Polling & Push

58

Engine.IOcommunication layer for Socket.IO

Page 59: How to build a scalable SNS via Polling & Push

59

Engine.IO - Socket.IO history0.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 ✓

Page 60: How to build a scalable SNS via Polling & Push

60

Engine.IO - Overview

Page 61: How to build a scalable SNS via Polling & Push

61

Engine.IO - Overview

● Ensure the most reliable realtime communication

Page 62: How to build a scalable SNS via Polling & Push

62

Engine.IO - Overview

● Ensure the most reliable realtime communication● Always establishes a long-polling connection first

Page 63: How to build a scalable SNS via Polling & Push

63

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

Page 64: How to build a scalable SNS via Polling & Push

64

Engine.IO - Upgrade transport seamlessly

Page 65: How to build a scalable SNS via Polling & Push

65

Engine.IO - Upgrade transport seamlessly

● Switches from polling to another transport in between polling cycles

Page 66: How to build a scalable SNS via Polling & Push

66

Engine.IO - Upgrade transport seamlessly

● 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

Page 67: How to build a scalable SNS via Polling & Push

67

Engine.IO

client server

Page 68: How to build a scalable SNS via Polling & Push

68

Engine.IO

client server

T0T1

Page 69: How to build a scalable SNS via Polling & Push

69

Engine.IO

client server

T0T1

Page 70: How to build a scalable SNS via Polling & Push

70

Engine.IO

client server

T0T1

Page 71: How to build a scalable SNS via Polling & Push

71

Engine.IO

client server

T0T1T6

T5

T7

Page 72: How to build a scalable SNS via Polling & Push

72

Engine.IO

client server

T0T1

T11

T6T5

T7T10

Page 73: How to build a scalable SNS via Polling & Push

73

Engine.IO

client server

T0T1

T11

T6T5

T7T10

Page 74: How to build a scalable SNS via Polling & Push

74

Engine.IO

client server

T0T1

T11

T6

T12T13

T14

T5

T7T10

Page 75: How to build a scalable SNS via Polling & Push

75

Engine.IO

● Pros– Auto-switch different network scenario

● Cons– Use particular protocol at server & client

Page 76: How to build a scalable SNS via Polling & Push

76

Polling & Push

Page 77: How to build a scalable SNS via Polling & Push

77

Why we don't use WebSocket

● Server– Many corporate proxies block WebSocket traffic

● Client– Many personal firewalls and antivirus softwares block

WebSocket traffic

Page 78: How to build a scalable SNS via Polling & Push

78

Push != Notification

Page 79: How to build a scalable SNS via Polling & Push

79

Push != Notification

Page 80: How to build a scalable SNS via Polling & Push

80

Push != NotificationPush Notification

Notification

Push Notification

Notification

Page 81: How to build a scalable SNS via Polling & Push

81

Push - Overview

● Non-IM– Breaking news notification– Remittance notification– Call off work notification– Email notification– ......etc.

● IM– Message notification

Page 82: How to build a scalable SNS via Polling & Push

82

How it works?

Page 83: How to build a scalable SNS via Polling & Push

83

When unsafe APIs done - Server

1.Store affected devices' ID & API ID to database

2.Send Push to affected devices

Page 84: How to build a scalable SNS via Polling & Push

84

When unsafe APIs done - Client

● Send an unified GET request– GET /datas

Page 85: How to build a scalable SNS via Polling & Push

85

When unsafe APIs done - Client

● Send an unified GET request– GET /datas

● Push off– apply frequency rapidly to achieve realtime, but waste

resources

Page 86: How to build a scalable SNS via Polling & Push

86

When unsafe APIs done - Client

● Send an unified GET request– GET /datas

● Push off– apply frequency rapidly to achieve realtime, but waste

resources● Push on

– apply frequency long to save resources– when Push comes, send request to get newest data to

achieve realtime

Page 87: How to build a scalable SNS via Polling & Push

87

Push - Push off

client server

Page 88: How to build a scalable SNS via Polling & Push

88

Push - Push off

client server

T0T1

T2

Page 89: How to build a scalable SNS via Polling & Push

89

Push - Push off

client server

T0T1

T2

T4T5

T6

Page 90: How to build a scalable SNS via Polling & Push

90

Push - Push off

client server

T0T1

T2

T4T5

T6

T8T9

T10

Page 91: How to build a scalable SNS via Polling & Push

91

Push - Push on

client server SNS

Page 92: How to build a scalable SNS via Polling & Push

92

Push - Push on

client server

T0T1

T2

SNS

Page 93: How to build a scalable SNS via Polling & Push

93

Push - Push on

client server

T0T1

T2

T22T23

T24

SNS

Page 94: How to build a scalable SNS via Polling & Push

94

Push - Push on

client server

T0T1

T2

T22T23

T24

SNS

T30

Page 95: How to build a scalable SNS via Polling & Push

95

Push - Push on

client server

T0T1

T2

T22T23

T24

T31T32

T33

SNS

T30

Page 96: How to build a scalable SNS via Polling & Push

96

Fallback

● Don't polling everything● Every GET APIs provide UI operation

Page 97: How to build a scalable SNS via Polling & Push

97

Fallback

Page 98: How to build a scalable SNS via Polling & Push

98

RESTful API design

Page 99: How to build a scalable SNS via Polling & Push

99

RESTful API Design

● HTTP method● Common examples● Is Graph API RESTful?● Actual example● Internal & Open API

Page 100: How to build a scalable SNS via Polling & Push

100

GET - Retrieve a resource

● A request to the server should never change the resource state

Page 101: How to build a scalable SNS via Polling & Push

101

GET - Retrieve a resource

● A request to the server should never change the resource state

● Incidental side effects are OK– Like logging

Page 102: How to build a scalable SNS via Polling & Push

102

GET - Retrieve a resource

● A request to the server should never change the resource state

● Incidental side effects are OK– Like logging

● Common response code– 200 OK

Page 103: How to build a scalable SNS via Polling & Push

103

GET - Retrieve a resource

● A request to the server should never change the resource state

● Incidental side effects are OK– Like logging

● Common response code– 200 OK– 301 Moved Permanently

Page 104: How to build a scalable SNS via Polling & Push

104

GET - Retrieve a resource

● A request to the server should never change the resource state

● Incidental side effects are OK– Like logging

● Common response code– 200 OK– 301 Moved Permanently– 404 Not Found (related to DELETE)– 410 Gone (related to DELETE)

Page 105: How to build a scalable SNS via Polling & Push

105

DELETE - Remove a resource

● A request to the server should destroy the resource & never refer to it again

Page 106: How to build a scalable SNS via Polling & Push

106

DELETE - Remove a resource

● A request to the server should destroy the resource & never refer to it again

● Common response code– 200 OK– 202 Accepted– 204 No Content

Page 107: How to build a scalable SNS via Polling & Push

107

POST

Page 108: How to build a scalable SNS via Polling & Push

108

POST

● POST-to-append

Page 109: How to build a scalable SNS via Polling & Push

109

POST

● POST-to-append● Overloaded POST

Page 110: How to build a scalable SNS via Polling & Push

110

POST-to-append

● A request to the server should create a new resource

Page 111: How to build a scalable SNS via Polling & Push

111

POST-to-append

● A request to the server should create a new resource

● Common response code– 201 Created

Page 112: How to build a scalable SNS via Polling & Push

112

POST-to-append

● A request to the server should create a new resource

● Common response code– 201 Created (plus "Location" header)

Page 113: How to build a scalable SNS via Polling & Push

113

POST-to-append

● A request to the server should create a new resource

● Common response code– 201 Created (plus "Location" header)– 202 Accepted

Page 114: How to build a scalable SNS via Polling & Push

114

Overloaded POST

● Providing a block of data, such as the result of submitting a form, to a data-handling process

Page 115: How to build a scalable SNS via Polling & Push

115

Overloaded POST

● Providing a block of data, such as the result of submitting a form, to a data-handling process

● "Data-handling process" can be anything

Page 116: How to build a scalable SNS via Polling & Push

116

Overloaded POST

● Providing a block of data, such as the result of submitting a form, to a data-handling process

● "Data-handling process" can be anything– POST /users/sort

Page 117: How to build a scalable SNS via Polling & Push

117

Overloaded POST

● Providing a block of data, such as the result of submitting a form, to a data-handling process

● "Data-handling process" can be anything– POST /users/sort– POST /login

Page 118: How to build a scalable SNS via Polling & Push

118

Overloaded POST

● Providing a block of data, such as the result of submitting a form, to a data-handling process

● "Data-handling process" can be anything– POST /users/sort– POST /login– ...etc.

Page 119: How to build a scalable SNS via Polling & Push

119

PUT - Update a resource

● A request to the server should modify the resource

Page 120: How to build a scalable SNS via Polling & Push

120

PUT - Update a resource

● A request to the server should modify the resource ● Common response code

– 200 OK– 204 No Content

Page 121: How to build a scalable SNS via Polling & Push

121

Idempotent & Safe

Page 122: How to build a scalable SNS via Polling & Push

122

Idempotent & Safe

● Idempotent– A HTTP method can be called many times without

different outcomes

Page 123: How to build a scalable SNS via Polling & Push

123

Idempotent & Safe

● Idempotent– A HTTP method can be called many times without

different outcomes● Safe

– Do not modify resources

Page 124: How to build a scalable SNS via Polling & Push

124

Idempotent & Safe

Idempotent Safe

GET yes yes

DELETE yes no

POST no no

PUT yes no

Page 125: How to build a scalable SNS via Polling & Push

125

Common examples

Page 126: How to build a scalable SNS via Polling & Push

126

GET /users

Page 127: How to build a scalable SNS via Polling & Push

127

GET /users

● Retrieve all users' brief

Page 128: How to build a scalable SNS via Polling & Push

128

GET /users

● Retrieve all users' brief{ "users": [ { "name": "kewang", "slogan": "Hello World" }, { "name": "Tony Stark", "slogan": "I'm Iron Man" }, { "name": "America captain", "slogan": "U.S.A." } ]}

Page 129: How to build a scalable SNS via Polling & Push

129

GET /users/:user_id

Page 130: How to build a scalable SNS via Polling & Push

130

GET /users/:user_id

● Retrieve a specific user information

Page 131: How to build a scalable SNS via Polling & Push

131

GET /users/:user_id

● Retrieve a specific user information

{ "name": "kewang", "slogan": "Hello World", "birthday": "19831108", "sex": 0, "email": [ "[email protected]", "[email protected]" ], "company": "mitake"}

Page 132: How to build a scalable SNS via Polling & Push

132

GET /users/:user_id/avatars

Page 133: How to build a scalable SNS via Polling & Push

133

GET /users/:user_id/avatars

● Retrieve a specific user's all avatars' URL

Page 134: How to build a scalable SNS via Polling & Push

134

GET /users/:user_id/avatars

● Retrieve a specific user's all avatars' URL{ "avatars": [ { "url": "http://www.s3.com/abc.png", "created": 1413385358 }, { "url": "http://www.s3.com/def.png", "created": 1401239876 }, { "url": "http://www.s3.com/ghi.png", "created": 1348303844 } ] }

Page 135: How to build a scalable SNS via Polling & Push

135

GET /users/:user_id/avatar

Page 136: How to build a scalable SNS via Polling & Push

136

GET /users/:user_id/avatar

● Retrieve a specific user's avatar URL

Page 137: How to build a scalable SNS via Polling & Push

137

GET /users/:user_id/avatar

● Retrieve a specific user's newest avatar URL

Page 138: How to build a scalable SNS via Polling & Push

138

GET /users/:user_id/avatar

● Retrieve a specific user's newest avatar URL

{ "url": "http://www.s3.com/abc.png"}

Page 139: How to build a scalable SNS via Polling & Push

139

Is Graph API RESTful?Facebook powered

Page 140: How to build a scalable SNS via Polling & Push

140

Graph API - Overview

Page 141: How to build a scalable SNS via Polling & Push

Graph API - Overview

● Everything is a "node" has a unique ID

Page 142: How to build a scalable SNS via Polling & Push

142

Graph API - Overview

● Everything is a "node" has a unique ID● Two nodes connect each other with a "edge"

Page 143: How to build a scalable SNS via Polling & Push

143

Graph API - Overview

● Everything is a "node" has a unique ID● Two nodes connect each other with a "edge"● A node information contains some "fields"

Page 144: How to build a scalable SNS via Polling & Push

144

Graph API - Are two people friends?

● GET /{user-a-id}/friends/{user-b-id}

Page 145: How to build a scalable SNS via Polling & Push

145

Graph API - Does someone like a Page?

● GET /{user-id}/likes/{page-id}

Page 146: How to build a scalable SNS via Polling & Push

146

Graph API - Publishing new Status Updates

● POST /{user-id}/feed● POST /{page-id}/feed

Page 147: How to build a scalable SNS via Polling & Push

147

Graph API - Uploading Photos

● POST /{user-id}/photos● POST /{page-id}/photos● POST /{album-id}/photos

Page 148: How to build a scalable SNS via Polling & Push

148

So, Graph API is RESTful?

Page 149: How to build a scalable SNS via Polling & Push

149

Graph API isn't RESTfulDeprecating the REST API

Page 150: How to build a scalable SNS via Polling & Push

150

An actual exampleKick a user from system

Page 151: How to build a scalable SNS via Polling & Push

151

V1 - Kick a user from system

Page 152: How to build a scalable SNS via Polling & Push

152

V1 - Kick a user from system

● Kick by myself

Page 153: How to build a scalable SNS via Polling & Push

153

V1 - Kick a user from system

● Kick by myself– DELETE /me

Page 154: How to build a scalable SNS via Polling & Push

154

V1 - Kick a user from system

● Kick by myself– DELETE /me

● Kick somebody

Page 155: How to build a scalable SNS via Polling & Push

155

V1 - Kick a user from system

● Kick by myself– DELETE /me

● Kick somebody– DELETE /:user_id

Page 156: How to build a scalable SNS via Polling & Push

156

V2 - Restore a user to system

Page 157: How to build a scalable SNS via Polling & Push

157

V2 - Restore a user to system

● PUT /:user_id

Page 158: How to build a scalable SNS via Polling & Push

158

V2 - Restore a user to system

● PUT /:user_id– Restore somebody to system

Page 159: How to build a scalable SNS via Polling & Push

159

V2 - Restore a user to system

● PUT /:user_id– Restore somebody to system– Change somebody information

Page 160: How to build a scalable SNS via Polling & Push

160

V3 - Update a user status

Page 161: How to build a scalable SNS via Polling & Push

161

V3 - Update a user status

● PUT /:user_id/status

Page 162: How to build a scalable SNS via Polling & Push

162

V3 - Update a user status

● PUT /:user_id/status– Kick somebody from system

Page 163: How to build a scalable SNS via Polling & Push

163

V3 - Update a user status

● PUT /:user_id/status– Kick somebody from system– Restore somebody to system

Page 164: How to build a scalable SNS via Polling & Push

164

Internal & Open API

Page 165: How to build a scalable SNS via Polling & Push

165

Internal API design guideline

Page 166: How to build a scalable SNS via Polling & Push

166

Internal API design guideline

● Minimize data size

Page 167: How to build a scalable SNS via Polling & Push

167

Internal API design guideline

● Minimize data size● Merge operations

Page 168: How to build a scalable SNS via Polling & Push

168

Internal API design guideline

● Minimize data size● Merge operations● Field names are short & convoluted

Page 169: How to build a scalable SNS via Polling & Push

169

Internal API design guideline

● Minimize data size● Merge operations● Field names are short & convoluted● Customize request & response for official apps

Page 170: How to build a scalable SNS via Polling & Push

170

Open API design guideline

Page 171: How to build a scalable SNS via Polling & Push

171

Open API design guideline

● Minimize data size

Page 172: How to build a scalable SNS via Polling & Push

172

Open API design guideline

● Minimize data size● Field names are simple & clear

Page 173: How to build a scalable SNS via Polling & Push

173

Open API design guideline

● Minimize data size● Field names are simple & clear● Build request & response generally

Page 174: How to build a scalable SNS via Polling & Push

174

Differences - GET /users

Internal API{

"us": [{

"id": "2d3f1a",

"nm": "Kewang",

"el": "[email protected]"

}, {

"id": "9a4f57",

"nm": "Hans",

"el": "[email protected]"

}]

}

Open API

{

"users": [{

"id": "2d3f1a",

"name": "Kewang"

}, {

"id": "9a4f57",

"name": "Hans"

}]

}

Page 175: How to build a scalable SNS via Polling & Push

175

API Blueprint

Page 176: How to build a scalable SNS via Polling & Push

176

API Blueprint

● Introduction● Aglio● API-Mock● Postman

Page 177: How to build a scalable SNS via Polling & Push

177

Introduction

● Web API Language● Pure Markdown● Design for Humans● Understandable by Machines● Powerful Tooling● Easy Lifecycle

Page 178: How to build a scalable SNS via Polling & Push

178

Hello World

Page 179: How to build a scalable SNS via Polling & Push

179

Complex example

Page 180: How to build a scalable SNS via Polling & Push

180

Aglio - API Blueprint renderer

Page 181: How to build a scalable SNS via Polling & Push

181

Aglio - Complex example

Page 182: How to build a scalable SNS via Polling & Push

182

API-Mock & Postman

Page 183: How to build a scalable SNS via Polling & Push

183

Live DEMO

Page 184: How to build a scalable SNS via Polling & Push

184

References

Page 185: How to build a scalable SNS via Polling & Push

185

References

Page 186: How to build a scalable SNS via Polling & Push

186

References

● Browser 與 Server 持續同步的作法介紹● Comet (programming)● Engine.IO: the realtime engine● Engine.IO Protocol● API Design Optimized for Mobile Platform● HTTP GET with request body● Does Google treat 404 and 410 status code differen

tly

Page 187: How to build a scalable SNS via Polling & Push

187

Page 188: How to build a scalable SNS via Polling & Push

188