how to build a scalable sns using hbase

167
How to build a scalable SNS using HBase Kewang 三竹資訊

Upload: mu-chun-wang

Post on 05-Dec-2014

603 views

Category:

Technology


1 download

DESCRIPTION

這場Talk將要分享如何使用HBase來建置一套可以延展的系統,大綱如下: 1. HBase brief introduction:簡單介紹HBase的運作原理 2. Rowkey(Schema) design:Rowkey的設計與AP的效能息息相關,如何設計Rowkey是HBase非常重要的一個課題 3. Best practice in Java:如何在操作HBase時,可以少碰一些雷 4. API Blueprint:分享如何將HBase設計出來的Dataflow,整理成文件 5. HBase Dataflow:可以利用這套工具,將設計出來的Dataflow傳承下去,利於保存 * Keyword: HBase, Rowkey Design, Dataflow * HBase Dataflow: http://kewangtw.github.io/hbase-dataflow

TRANSCRIPT

Page 1: How to build a scalable SNS using HBase

How to build a scalable SNS using HBase

Kewang

三竹資訊

Page 2: How to build a scalable SNS using HBase

Who I am

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

Github: kewangtw

Facebook: kewangtw

Linkedin: kewangtw

Slideshare: kewang

Mail: [email protected]

Page 3: How to build a scalable SNS using HBase

Who Mitake is

三竹資訊

Page 4: How to build a scalable SNS using HBase

Who Mitake is

三竹資訊

大家都唸Mitake

Page 5: How to build a scalable SNS using HBase

Who Mitake is

三竹資訊

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

Page 6: How to build a scalable SNS using HBase

Who Mitake is

三竹資訊

Mitake不唸作MiTAC啊!!!

Page 7: How to build a scalable SNS using HBase

Who Mitake is

三竹資訊

Page 8: How to build a scalable SNS using HBase

Who Mitake is

三竹資訊● 簡訊平台

Page 9: How to build a scalable SNS using HBase

Who Mitake is

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

Page 10: How to build a scalable SNS using HBase

Who Mitake is

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

Page 11: How to build a scalable SNS using HBase

Who Mitake is

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

Page 12: How to build a scalable SNS using HBase

Who Mitake is

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

Page 13: How to build a scalable SNS using HBase

Who Mitake is

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

Page 14: How to build a scalable SNS using HBase

Who Mitake is

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

Page 15: How to build a scalable SNS using HBase

Who Mitake is

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

Page 16: How to build a scalable SNS using HBase

Who Mitake is

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

Page 17: How to build a scalable SNS using HBase

Who Mitake is

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

Page 18: How to build a scalable SNS using HBase

System Architecture

Page 19: How to build a scalable SNS using HBase

19

System Architecture

Page 20: How to build a scalable SNS using HBase

20

System Architecture (Backend)

Page 21: How to build a scalable SNS using HBase

21

System Architecture (Frontend)

Page 22: How to build a scalable SNS using HBase

22

System Architecture (Frontend)

MOPCON 2014 CfP

Page 23: How to build a scalable SNS using HBase

23

Agenda

● Rowkey design● Best Practice in Java● API Blueprint● HBase Dataflow

Page 24: How to build a scalable SNS using HBase

24

Rowkey design

Page 25: How to build a scalable SNS using HBase

25

Rowkey design - Avoid hotspotting

Page 26: How to build a scalable SNS using HBase

26

Rowkey design - Avoid hotspotting

● Sorted lexicographically

Page 27: How to build a scalable SNS using HBase

27

Rowkey design - Avoid hotspotting

● Sorted lexicographically

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

Page 28: How to build a scalable SNS using HBase

28

Rowkey design - Avoid hotspotting

● Sorted lexicographically

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

Page 29: How to build a scalable SNS using HBase

29

Rowkey design - Avoid hotspotting

● Sorted lexicographically

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

Page 30: How to build a scalable SNS using HBase

30

Rowkey design - Avoid hotspotting

● Salting, Hashing or Reversing

Page 31: How to build a scalable SNS using HBase

31

Rowkey design - Avoid hotspotting

● Salting, Hashing or Reversing

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

Page 32: How to build a scalable SNS using HBase

32

Rowkey design - Avoid hotspotting

● Salting, Hashing or Reversing

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

BOX

Page 33: How to build a scalable SNS using HBase

33

Rowkey design - Avoid hotspotting

● Salting, Hashing or Reversing

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

BOX

Page 34: How to build a scalable SNS using HBase

34

Rowkey design - Avoid hotspotting

● Salting, Hashing or Reversing

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

BOX

a-foo-1

Page 35: How to build a scalable SNS using HBase

35

Rowkey design - Avoid hotspotting

● Salting, Hashing or Reversing

Region 3

Region 1

Region 2

foo-1

foo-2

foo-3

foo-4

BOX

a-foo-1

b-foo-2

c-foo-3d-foo-4

Page 36: How to build a scalable SNS using HBase

36

Rowkey design - Refining ID

Page 37: How to build a scalable SNS using HBase

37

Rowkey design - Refining ID

● SHA1: 40 bytes– 3204c3aefcca4a556f0f7547d056235fa823af3a

Page 38: How to build a scalable SNS using HBase

38

Rowkey design - Refining ID

● SHA1: 40 bytes– 3204c3aefcca4a556f0f7547d056235fa823af3a

● UUID: 36 bytes– 22bfad60-39d2-11e4-916c-0800200c9a66

Page 39: How to build a scalable SNS using HBase

39

Rowkey design - Refining ID

● SHA1: 40 bytes– 3204c3aefcca4a556f0f7547d056235fa823af3a

● UUID: 36 bytes– 22bfad60-39d2-11e4-916c-0800200c9a66

● MD5: 32 bytes– 27734b3f4f98e709f58c6ddb0193164e

Page 40: How to build a scalable SNS using HBase

Too long !!!

Page 41: How to build a scalable SNS using HBase

41

Rowkey design - Refining ID

● X Algorithm

Page 42: How to build a scalable SNS using HBase

42

Rowkey design - Refining ID

● X Algorithm: 12 bytes

Page 43: How to build a scalable SNS using HBase

43

Rowkey design - Refining ID

● X Algorithm: 12 bytes– Auto increment

Page 44: How to build a scalable SNS using HBase

44

Rowkey design - Refining ID

● X Algorithm: 12 bytes– Auto increment– Ordered

Page 45: How to build a scalable SNS using HBase

45

Rowkey design - Refining ID

● X Algorithm: 12 bytes– Auto increment– Ordered– Counts to 2.17E21

Page 46: How to build a scalable SNS using HBase

Rowkey design - Refining ID

● X Algorithm: 12 bytes– Auto increment– Ordered– Counts to 2.17E21– e.g: H00000001B12

Page 47: How to build a scalable SNS using HBase

47

Rowkey design - Authenticating

Page 48: How to build a scalable SNS using HBase

48

Rowkey design - Authenticating

● Get frequently

Page 49: How to build a scalable SNS using HBase

49

Rowkey design - Authenticating

● Get frequently

User Id ID0000001A3B

Access Token d66e3b70-3666-11e4-8c21-0800200c9a66

Expired Time 1410077636

Page 50: How to build a scalable SNS using HBase

50

Rowkey design - Authenticating

● Get frequently● Multi-login

Page 51: How to build a scalable SNS using HBase

51

Rowkey design - Authenticating

● Get frequently● Multi-login

User Id ID0000001A3B

Token 0 d66e3b70-3666-11e4-8c21-0800200c9a66+1410077636+Device1

Token 1 92e84bf9-7852-492d-b56a-13ba7acb8fb5+1410123456+Device2

Page 52: How to build a scalable SNS using HBase

52

Rowkey design - Rice dumpling

Page 53: How to build a scalable SNS using HBase

53

Rowkey design - Rice dumpling

Page 54: How to build a scalable SNS using HBase

54

Rowkey design - Rice dumpling

Page 55: How to build a scalable SNS using HBase

55

Rowkey design - Rice dumpling

Id ME00000024AC

Title Announce

Content We are hiring

Page 56: How to build a scalable SNS using HBase

56

Rowkey design - Rice dumpling

Id ME00000024AC

Title Announce

Content We are hiring

Id ME00000024AC.ME00000037ZZ

Title (n/a)

Content I want to join your team !!!

Page 57: How to build a scalable SNS using HBase

57

Rowkey design - Rice dumpling

Id ME00000024AC

Title Announce

Content We are hiring

Id ME00000024AC.ME00000037ZZ

Title (n/a)

Content I want to join your team !!!

Page 58: How to build a scalable SNS using HBase

58

Rowkey design - Access controlling

Page 59: How to build a scalable SNS using HBase

59

Rowkey design - Access controlling

Page 60: How to build a scalable SNS using HBase

60

Rowkey design - Access controlling

Only A, B can see it.

Page 61: How to build a scalable SNS using HBase

61

Rowkey design - Access controlling

Only A, B can see it.Of course, including me.

Page 62: How to build a scalable SNS using HBase

62

Rowkey design - Access controlling

● When post a message (Write)

Page 63: How to build a scalable SNS using HBase

63

Rowkey design - Access controlling

● When post a message (Write)– Generate ACL Id

Page 64: How to build a scalable SNS using HBase

64

Rowkey design - Access controlling

● When post a message (Write)– Generate ACL Id– Put ACL Id to message, and reader's ACLs

Page 65: How to build a scalable SNS using HBase

65

Rowkey design - Access controlling

● When post a message (Write)– Generate ACL Id– Put ACL Id to message, and reader's ACLs

● When read my messages (Read)

Page 66: How to build a scalable SNS using HBase

66

Rowkey design - Access controlling

● When post a message (Write)– Generate ACL Id– Put ACL Id to message, and reader's ACLs

● When read my messages (Read)– Scan my ACLs, and all messages

Page 67: How to build a scalable SNS using HBase

67

Rowkey design - Access controlling

● When post a message (Write)– Generate ACL Id– Put ACL Id to message, and reader's ACLs

● When read my messages (Read)– Scan my ACLs, and all messages– If my ACLs contains message's ACL Id, can SHOW it

Page 68: How to build a scalable SNS using HBase

68

Rowkey design - Access controlling

Write

Page 69: How to build a scalable SNS using HBase

69

Rowkey design - Access controlling

ACL hash hash(A, B, K)+C+R

ACL Id AI0070ADWrite

Page 70: How to build a scalable SNS using HBase

70

Rowkey design - Access controlling

ACL hash hash(A, B, K)+C+R

ACL Id AI0070AD

Message Id ME00000024AC

Title Announce

Content We are hiring

ACL Id AI0070AD

Write

Page 71: How to build a scalable SNS using HBase

71

Rowkey design - Access controlling

ACL Id+User Id AI0070AD+A AI0070AD+B AI0070AD+K

Create 1 1 1

Read 1 1 1

Update 0 0 0

Delete 0 0 0Write

Page 72: How to build a scalable SNS using HBase

72

Rowkey design - Access controlling

User Id+ACL Id A+AI0070AD B+AI0070AD K+AI0070ADCreate 1 1 1Read 1 1 1Update 0 0 0Delete 0 0 0

ACL Id+User Id AI0070AD+A AI0070AD+B AI0070AD+K

Create 1 1 1

Read 1 1 1

Update 0 0 0

Delete 0 0 0Write

Page 73: How to build a scalable SNS using HBase

73

Rowkey design - Access controlling

Read

Page 74: How to build a scalable SNS using HBase

74

Rowkey design - Access controllingUser Id+ACL Id K+AI0070AD K+AI028577

Create 1 1

Read 1 1

Update 0 1

Delete 0 1

Read

Page 75: How to build a scalable SNS using HBase

75

Rowkey design - Access controllingUser Id+ACL Id K+AI0070AD K+A1028577

Create 1 1

Read 1 1

Update 0 1

Delete 0 1

Read

Message Id ME00000024AC

Title Announce

Content We are hiring

ACL Id AI0070AD

Page 76: How to build a scalable SNS using HBase

76

Rowkey design - Access controllingUser Id+ACL Id K+AI0070AD K+A1028577

Create 1 1

Read 1 1

Update 0 1

Delete 0 1

Read

Message Id ME00000024AC

Title Announce

Content We are hiring

ACL Id AI0070AD

Page 77: How to build a scalable SNS using HBase

77

Rowkey design - Statistics

Page 78: How to build a scalable SNS using HBase

78

Rowkey design - Statistics

● Variety of types– e.g., Likes, Comments, Registrations

Page 79: How to build a scalable SNS using HBase

79

Rowkey design - Statistics

● Variety of types– e.g., Likes, Comments, Registrations

● By unit– i.e., hourly, daily, weekly, monthly, yearly

Page 80: How to build a scalable SNS using HBase

80

Rowkey design - Statistics

● Variety of types– e.g., Likes, Comments, Registrations

● By unit– i.e., hourly, daily, weekly, monthly, yearly

● By user

Page 81: How to build a scalable SNS using HBase

81

Rowkey design - Statistics

Unit+Time Base+User Id+Type H+20140908+AAA+Like

11 7

15 22

21 15

Unit+Time Base+User Id+Type D+201409+AAA+Like

08 44

11 58

Page 82: How to build a scalable SNS using HBase

82

Rowkey design - Statistics

● Sum counts from 2014/9/7 to 2014/9/20 group by user or counting type

Unit+Time Base+User Id+Type D+201409+AAA+Like

02 20

08 52

09 41

... ...

20 55

Page 83: How to build a scalable SNS using HBase

83

Rowkey design - Statistics

● Sum counts from 2014/9/7 to 2014/9/20 group by user or counting type

Unit+Time Base+User Id+Type D+201409+AAA+Like

02 20

08 52

09 41

... ...

20 55

Page 84: How to build a scalable SNS using HBase

84

Rowkey design - Statistics

● Sum AAA's counts from 2014/9/7 to 2014/9/20 group by counting type

Unit+Time Base+User Id+Type D+201409+AAA+Like

02 20

08 52

09 41

... ...

20 55

Page 85: How to build a scalable SNS using HBase

85

Rowkey design - Statistics

● Sum AAA's like counts from 2014/9/7 to 2014/9/20

Unit+Time Base+User Id+Type D+201409+AAA+Like

02 20

08 52

09 41

... ...

20 55

Page 86: How to build a scalable SNS using HBase

86

Rowkey design - Summary

● Avoid hotspotting● Refining ID● Authenticating● Rice dumpling● Access controlling● Statistics

Page 87: How to build a scalable SNS using HBase

87

Best Practice in Java

Page 88: How to build a scalable SNS using HBase

88

No. 1

Page 89: How to build a scalable SNS using HBase

89

No. 1

USE HashMap

Page 90: How to build a scalable SNS using HBase

90

No. 1

USE HashMapNoSQL is different from RDBMS

Page 91: How to build a scalable SNS using HBase

91

No. 1 USE HashMap

OLD

Page 92: How to build a scalable SNS using HBase

92

No. 1 USE HashMappublic class Validation1 { private String accessToken; private long expiredTime;

public Validation1() { accessToken = null; expiredTime = -1; } public String getAccessToken() { return accessToken; } public void setAccessToken(String accessToken) { this.accessToken = accessToken; } public long getExpiredTime() { return expiredTime; } public void setExpiredTime(long expiredTime) { this.expiredTime = expiredTime; }}

OLD

Page 93: How to build a scalable SNS using HBase

93

No. 1 USE HashMap

NEW

Page 94: How to build a scalable SNS using HBase

94

No. 1 USE HashMappublic static final String ACCESS_TOKEN = "access token";

private Map<String, byte[]> putMap;

public Validation1() { super();}

public Validation1(Result result) { super(result);}

public String getAccessToken() { return Bytes.toString(putMap.get(ACCESS_TOKEN));}

public void setAccessToken(String accessToken) { putMap.put(ACCESS_TOKEN, Bytes.toBytes(accessToken));}

NEW

Page 95: How to build a scalable SNS using HBase

95

No. 1 USE HashMappublic static final String ACCESS_TOKEN = "access token";

private Map<String, byte[]> putMap;

public Validation1() { super();}

public Validation1(Result result) { super(result);}

public String getAccessToken() { return Bytes.toString(putMap.get(ACCESS_TOKEN));}

public void setAccessToken(String accessToken) { putMap.put(ACCESS_TOKEN, Bytes.toBytes(accessToken));}

NEW

Page 96: How to build a scalable SNS using HBase

96

No. 1 USE HashMap

● Bytes.toXXX() returns always Type XXX or NULL

Page 97: How to build a scalable SNS using HBase

97

No. 1 USE HashMap

● Bytes.toXXX() returns always Type XXX or NULL– Or throws Exception

Page 98: How to build a scalable SNS using HBase

No. 1 USE HashMap

● Bytes.toXXX() returns always Type XXX or NULL– Or throws Exception

● Improve default value in Java

Page 99: How to build a scalable SNS using HBase

99

No. 2

Page 100: How to build a scalable SNS using HBase

100

No. 2

ONE table, MULTI domains

Page 101: How to build a scalable SNS using HBase

101

No. 2

ONE table, MULTI domainsNoSQL is different from RDBMS

Page 102: How to build a scalable SNS using HBase

102

No. 2 ONE table, MULTI domains

● In RDBMS–

● In NoSQL–

Page 103: How to build a scalable SNS using HBase

103

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)–

● In NoSQL–

Page 104: How to build a scalable SNS using HBase

104

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)–

● In NoSQL (at runtime)–

Page 105: How to build a scalable SNS using HBase

105

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)– Primary key affects only one column–

● In NoSQL (at runtime)–

Page 106: How to build a scalable SNS using HBase

106

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)– Primary key affects only one column–

● In NoSQL (at runtime)– Rowkey always changes–

Page 107: How to build a scalable SNS using HBase

107

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)– Primary key affects only one column– Schema is fixed–

● In NoSQL (at runtime)– Rowkey always changes–

Page 108: How to build a scalable SNS using HBase

108

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)– Primary key affects only one column– Schema is fixed–

● In NoSQL (at runtime)– Rowkey always changes– Schema always changes–

Page 109: How to build a scalable SNS using HBase

109

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)– Primary key affects only one column– Schema is fixed– DAO serves one domain

● In NoSQL (at runtime)– Rowkey always changes– Schema always changes–

Page 110: How to build a scalable SNS using HBase

110

No. 2 ONE table, MULTI domains

● In RDBMS (at design time)– Primary key affects only one column– Schema is fixed– DAO serves one domain

● In NoSQL (at runtime)– Rowkey always changes– Schema always changes– DAO serves many domains

Page 111: How to build a scalable SNS using HBase

111

No. 2 ONE table, MULTI domains

User Id ID0000001A3B

Access Token d66e3b70-3666-11e4-8c21-0800200c9a66

Expired Time 1410077636

Page 112: How to build a scalable SNS using HBase

112

No. 2 ONE table, MULTI domains

User Id ID0000001A3B

Access Token d66e3b70-3666-11e4-8c21-0800200c9a66

Expired Time 1410077636

User Id+ACL Id ID0000001A3B+AI0070AD

Create 1

Read 1

Update 0

Delete 0

Page 113: How to build a scalable SNS using HBase

113

No. 2 ONE table, MULTI domains

User Id ID0000001A3B

Access Token d66e3b70-3666-11e4-8c21-0800200c9a66

Expired Time 1410077636

User Id+ACL Id ID0000001A3B+AI0070AD

Create 1

Read 1

Update 0

Delete 0

Page 114: How to build a scalable SNS using HBase

114

No. 2 ONE table, MULTI domains

● A DAO maps to a domain in RDBMS

Page 115: How to build a scalable SNS using HBase

115

No. 2 ONE table, MULTI domains

● A DAO maps to a domain in RDBMS

DB DAO Domain A

Page 116: How to build a scalable SNS using HBase

116

No. 2 ONE table, MULTI domains

● A DAO maps to multiple domains in NoSQL

Page 117: How to build a scalable SNS using HBase

117

No. 2 ONE table, MULTI domains

● A DAO maps to multiple domains in NoSQL

DB DAO

Domain A1

Domain A2

Domain A3

Page 118: How to build a scalable SNS using HBase

118

No. 2 ONE table, MULTI domains

● A DAO maps to multiple domains in NoSQL● Build a middle layer to translate multiple domains

DB DAO

Domain A1

Domain A2

Domain A3

Page 119: How to build a scalable SNS using HBase

119

No. 2 ONE table, MULTI domains

● A DAO maps to multiple domains in NoSQL● Build a middle layer to translate multiple domains

DB DAO

Domain A1

Domain A2

Domain A3

Schema

Page 120: How to build a scalable SNS using HBase

120

No. 2 ONE table, MULTI domains

● A DAO maps to multiple domains in NoSQL● Build a middle layer to translate multiple domains

DB DAO

Domain A1

Domain A2

Domain A3

Schema

Page 121: How to build a scalable SNS using HBase

121

No. 2 ONE table, MULTI domains

private String checkDomainType(Result result) { if (result.isEmpty()) { return null; } else { String rowkey = Bytes.toString(result.getRow()); String[] splitKey = rowkey.split(DIVIDER);

if (splitKey.length == 1) {

} }}

Page 122: How to build a scalable SNS using HBase

122

No. 2 ONE table, MULTI domains

private String checkDomainType(Result result) { if (result.isEmpty()) { return null; } else { String rowkey = Bytes.toString(result.getRow()); String[] splitKey = rowkey.split(DIVIDER);

if (splitKey.length == 1) { return DOMAIN_TYPE_VALIDATION1; } }}

Page 123: How to build a scalable SNS using HBase

123

No. 2 ONE table, MULTI domains

private String checkDomainType(Result result) { if (result.isEmpty()) { return null; } else { String rowkey = Bytes.toString(result.getRow()); String[] splitKey = rowkey.split(DIVIDER);

if (splitKey.length == 1) { return DOMAIN_TYPE_VALIDATION1; } else if (splitKey.length == 2) { return DOMAIN_TYPE_VALIDATION2; } }}

Page 124: How to build a scalable SNS using HBase

124

No. 2 ONE table, MULTI domains

private String checkDomainType(Result result) { if (result.isEmpty()) { return null; } else { String rowkey = Bytes.toString(result.getRow()); String[] splitKey = rowkey.split(DIVIDER);

if (splitKey.length == 1) { return DOMAIN_TYPE_VALIDATION1; } else if (splitKey.length == 2) { return DOMAIN_TYPE_VALIDATION2; } else { return DOMAIN_TYPE_VALIDATION3; } }}

Page 125: How to build a scalable SNS using HBase

125

No. 2 ONE table, MULTI domains

private String checkDomainType(Result result) { if (result.isEmpty()) { return null; } else { String rowkey = Bytes.toString(result.getRow()); String[] splitKey = rowkey.split(DIVIDER);

if (splitKey.length == 1) { return DOMAIN_TYPE_VALIDATION1; } else if (splitKey.length == 2) { return DOMAIN_TYPE_VALIDATION2; } else { return DOMAIN_TYPE_VALIDATION3; } }}

Customize

Page 126: How to build a scalable SNS using HBase

126

No. 3

Page 127: How to build a scalable SNS using HBase

127

No. 3

NoSQL is different from RDBMS

Page 128: How to build a scalable SNS using HBase

128

No. 3

NoSQL is different from RDBMSREALLY !!!

Page 129: How to build a scalable SNS using HBase

129

API Blueprint

Page 130: How to build a scalable SNS using HBase

130

Page 131: How to build a scalable SNS using HBase

131

API Blueprint - Introduction

Page 132: How to build a scalable SNS using HBase

132

API Blueprint - Introduction

● Web API Language

Page 133: How to build a scalable SNS using HBase

133

API Blueprint - Introduction

● Web API Language● Pure Markdown

Page 134: How to build a scalable SNS using HBase

134

API Blueprint - Introduction

● Web API Language● Pure Markdown● Design for Humans

Page 135: How to build a scalable SNS using HBase

135

API Blueprint - Introduction

● Web API Language● Pure Markdown● Design for Humans● Understandable by Machines

Page 136: How to build a scalable SNS using HBase

136

API Blueprint - Introduction

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

Page 137: How to build a scalable SNS using HBase

137

API Blueprint - Introduction

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

Page 138: How to build a scalable SNS using HBase

138

API Blueprint - Hello World

Page 139: How to build a scalable SNS using HBase

139

API Blueprint - Hello World

Page 140: How to build a scalable SNS using HBase

140

API Blueprint - Complex

Page 141: How to build a scalable SNS using HBase

141

API Blueprint - Complex

Page 142: How to build a scalable SNS using HBase

142

HBase dataflow

Page 143: How to build a scalable SNS using HBase

143

HBase dataflowconserve your domain know-how

Page 144: How to build a scalable SNS using HBase

144

HBase dataflow - Solve what ?

Page 145: How to build a scalable SNS using HBase

145

HBase dataflow - Solve what ?

● How to conserve system know-how about Put, Get, Scan or other operations in HBase ?

Page 146: How to build a scalable SNS using HBase

146

Paper & Pen ?

Page 147: How to build a scalable SNS using HBase

147

Paper & Pen ?

Page 148: How to build a scalable SNS using HBase

148

Redmine / KM ?

Page 149: How to build a scalable SNS using HBase

149

Redmine / KM ?

Page 150: How to build a scalable SNS using HBase

150http://kewangtw.github.io/hbase-dataflow/

Page 151: How to build a scalable SNS using HBase

151

HBase dataflow - introduction

Page 152: How to build a scalable SNS using HBase

152

HBase dataflow - introduction

● HBase operation - Put, Delete, Get, Scan, Filters

Page 153: How to build a scalable SNS using HBase

153

HBase dataflow - introduction

● HBase operation - Put, Delete, Get, Scan, Filters● Export

Page 154: How to build a scalable SNS using HBase

154

HBase dataflow - introduction

● HBase operation - Put, Delete, Get, Scan, Filters● Export

– to JSON / Markdown

Page 155: How to build a scalable SNS using HBase

155

HBase dataflow - introduction

● HBase operation - Put, Delete, Get, Scan, Filters● Export

– to JSON / Markdown– to PNG / PDF

Page 156: How to build a scalable SNS using HBase

156

HBase dataflow - introduction

● HBase operation - Put, Delete, Get, Scan, Filters● Export

– to JSON / Markdown– to PNG / PDF

● Import from JSON

Page 157: How to build a scalable SNS using HBase

157

HBase dataflow - introduction

● HBase operation - Put, Delete, Get, Scan, Filters● Export

– to JSON / Markdown– to PNG / PDF

● Import from JSON● Write title & summary

Page 158: How to build a scalable SNS using HBase

158

HBase dataflow - introduction

● HBase operation - Put, Delete, Get, Scan, Filters● Export

– to JSON / Markdown– to PNG / PDF

● Import from JSON● Write title & summary● Open source

Page 159: How to build a scalable SNS using HBase

159

Live DEMO

Page 160: How to build a scalable SNS using HBase

160

Design API Step by Step

Page 161: How to build a scalable SNS using HBase

161

Design API Step by Step

1.Paper & pen always are your friends

Page 162: How to build a scalable SNS using HBase

162

Design API Step by Step

1.Paper & pen always are your friends

2.Use HBase dataflow to simulate data's flow

Page 163: How to build a scalable SNS using HBase

163

Design API Step by Step

1.Paper & pen always are your friends

2.Use HBase dataflow to simulate data's flow

3.Export it

Page 164: How to build a scalable SNS using HBase

164

Page 166: How to build a scalable SNS using HBase

166

Page 167: How to build a scalable SNS using HBase

167