i love apis 2015: apache usergrid web scale mobile apis with elastic search and cassandra

44
1 Apache Usergrid: Web Scale Mobile APIs with ElasticSearch and Cassandra Todd Nine Principal Architect Jeffrey West BaaS Engineering Coach

Upload: apigee

Post on 19-Jan-2017

863 views

Category:

Software


4 download

TRANSCRIPT

Page 1: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

1

Apache Usergrid: Web Scale Mobile APIs with ElasticSearch and Cassandra !

Todd Nine Principal Architect

Jeffrey West BaaS Engineering

Coach

Page 2: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Agenda

2

1. Why do we need Usergrid? 2. What is Usergrid & How does it work? 3. How do we achieve web scale? 4. Learnings 5. Roadmap & Questions

©2015 Apigee. All Rights Reserved.

Page 3: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

3

(m) obile B ackend a s a S ervice

Datastore

Push Notifications

Connections /Social

Location

Users

…and more

Application

Page 4: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Systems of Engagement

4

Page 5: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Building Systems of Engagement with Edge API BaaS

5

Systems of "Record

Apigee Edge: Intelligent API Platform

Systems of Engagement

App Developers

Database ERP CRM Data "Warehouse Data Lake

Partner Apps Consumer Apps Employee Apps Insights

Page 6: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

6 ©2015 Apigee. All Rights Reserved.

Web Scale"10’s of thousands requests/sec"…across multiple data centers

Page 7: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

7 ©2015 Apigee. All Rights Reserved.

Web Scale / MongoDB

Page 8: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Usergrid

8

Page 9: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

• Apache Open Source Mobile Backend as a Service • REST API for easy interaction from any platform • SDKs available for iOS / Android / Javascript

9

Page 10: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

The Usergrid Taxonomy

10

Page 11: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Organization Organization

Organization

Application

Devices Users Groups

Security Roles

Collection Collection

Entity {…} Entity

{…} Entity {…}

Application

Devices Users Groups

Security Roles

Entity {…} Entity

{…} Entity {…}

Collection Collection

Entity {…} Entity

{…} Entity {…}

Page 12: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

But I just want persistence!

12 ©2015 Apigee. All Rights Reserved.

REST API GET / PUT / POST / DELETE

Scalable, Multi-tenant Persistence (Single Cluster)

Page 13: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

What people do seeking ‘web scale’?

13 ©2015 Apigee. All Rights Reserved.

Page 14: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

The Usergrid Stack

14

Page 15: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

•  Canonical System of Record

•  Collections –  Unique Values / Primary Keys

•  Entities –  Schemaless design –  O(1) entity retrieval

•  Connections / Graph –  Scalable Relationships

Horizontally Scalable Persistence

Page 16: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Built on Horizontally Scalable Technologies

• Filter / Limit / Cursor: – GET http://api.usergrid.com/{org}/{app}/{collection}?ql=select * where title = 'A Tale of Two Cities’&limit=50&cursor=LTIxNDg0NDUxNDpnR2tBQVFFQWdITUFDWFJ2YlM1emJXbDBhQUNBZFFBUUQyMVZneExfRWVLRlV3TG9Hc1doZXdDQWRRQVFIYVdjb0JwREVlS1VCd0xvR3NWT0JRQQ

– GET http://api.usergrid.com/{org}/{app}/{collection}?ql=select * where location within {d} of {x, y}

17 ©2015 Apigee. All Rights Reserved.

( )

Page 17: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Usergrid Application

18 ©2015 Apigee. All Rights Reserved.

Page 18: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Architecture: Multi-Region Indexing & Consistency

SQS SQS SNS

6) INDEX 6) INDEX

Region B Region A C* Replication

2) WRITE 5)

REA

D

5) R

EAD

Page 19: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Web Scale

20

Page 20: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Bottlenecks

21 ©2015 Apigee. All Rights Reserved.

Tomcat 20% CPU !?? WHY ??! Cassandra

10% CPU

Page 21: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Iterative Process

22 ©2015 Apigee. All Rights Reserved.

10,266/s 9,700/s

7,233/s

3,750

Page 22: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Hurdles •  Gatling

–  Can’t get 10k/s with one node •  Cassandra

–  CPU •  Compression? •  C3.2xlarge -> c3.4xlarge •  Row caching?

•  Tomcat –  HTTP Connector

•  acceptCount •  maxConnections •  maxThreads •  Non-blocking IO?

•  Usergrid –  # of reads to Cassandra

23 ©2015 Apigee. All Rights Reserved.

Page 23: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Scaling Usergrid to 10,000 Req/s w/ Gatling

•  10k test run: –  35 c3.xlarge Tomcat Nodes –  9 c3.4xlarge C* nodes –  6 m3.large ES nodes

•  Closing test ~7,800/s: –  15 c3.xlarge Tomcat Nodes –  9 c3.4xlarge C* nodes –  6 m3.large ES nodes

24

Page 24: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Elasticsearch(working… not so well…)

25

Page 25: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Learn from our mistakes

26

Page 26: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Risks of Dynamic Mapping

27 ©2015 Apigee. All Rights Reserved.

D

D

D

D M

Page 27: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Risks of Dynamic Mapping

28 ©2015 Apigee. All Rights Reserved.

DD

D

DD

DD

DDD

D D

DD

DD

DD

DD

Inbound message requires a mapping

update

Mapping updated & broadcast to the

cluster M

Page 28: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Risks of Dynamic Mapping

29 ©2015 Apigee. All Rights Reserved.

M

DD

D

DD

DD

DDD

D D

DD

DD

DD

DD

At scale (full loaded) only one mapping

update can processed at a time

Page 29: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Risks of Dynamic Mapping

30 ©2015 Apigee. All Rights Reserved.

DD

D

DD

DD

DDD

D D

DD

DD

DD

DD

M

Page 30: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Risks of Dynamic Mapping

31 ©2015 Apigee. All Rights Reserved.

M

DD

D

DD

DD

DDD

D D

DD

DD

DD

DD

Page 31: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

30 ES Data Nodes X

100MB mapping file =

3,000MB

For each schema/mapping update

3GB data transfer X

5M entities with different schemas

= a LOT of data

transfer and a lot of latency

Risks of Dynamic Mapping

32 ©2015 Apigee. All Rights Reserved.

DD

D

DD

DD

DDD

D D

DD

DD

DD

DD

M

Page 32: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Elasticsearch(working well)

33

Page 33: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

{ "hello": { "world":{ "message": "Hello!" }, "items": [ { "name": "apples", "weight": 100 } ] } }

{ "uuid": "48e262d6-b922-11e4-8a11", "ud_entity_id": "ad2b33c2e", "size": 100, "ug_app": "1a67aed7-bbb3-11e4-8a11", "fields": [ { ”name": "hello.world.message", ”string": "Hello!" }, { ”name": "items[0].name", ”string": "apples" }, { ”name": "items[0].weight", "integer": 100 } ] }

Flattened Documents

34 ©2015 Apigee. All Rights Reserved.

Indexed as

Page 34: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Data Node A

Data Node B

Data Node C

Index Allocation •  Multiple Indexes spread across the cluster •  Indexes have shards •  Read/Write aliases point to physical

indexes •  Aliases assigned based on hashing of the

App UUID

35 ©2015 Apigee. All Rights Reserved.

Index_1

1

1

2

3 2

3

app_1_read_alias app_1_write_alias

Page 35: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Data Node A

Data Node B

Data Node C

Tenant Management

36 ©2015 Apigee. All Rights Reserved.

Index_1

1

1

2

3 2

3

app_1_read_alias

app_1_write_alias

app_2_read_alias

app_2_write_alias

Page 36: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Data Node A

Data Node B

Data Node C

Tenant Management •  Assign Write alias to new Index •  Add new index to read alias •  Stream data from old index •  Delete data from old index

37 ©2015 Apigee. All Rights Reserved.

Index_1

1

1

2

3 2

3

Index_2

1

1

2

3

2 3

app_2_read_alias

app_2_write_alias

stream2es

app_1_read_alias

app_1_write_alias

Page 37: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Data Node D

Data Node A

Data Node B

Data Node C

Tenant Management •  Indexes targeted to separate machines

38 ©2015 Apigee. All Rights Reserved.

Index_1

1

1

2

3 2

3

Index_2

1

1

2

3 2

3

app_1_read_alias app_1_write_alias app_2_read_alias

app_2_write_alias

Page 38: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Data Node A

Data Node B

Data Node C

Data Node A

Data Node B

Data Node C

Multiple Scaling Vectors

39 ©2015 Apigee. All Rights Reserved.

Index_1

1

1

2

3 2

3

Index_2

1

1

2

3 2

3

Index_3

1

1 2

3

2 3

Index_4

1

1 2

3 2

3

Index_5

1

1

2

3 2

3

Page 39: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Working with Graph & NoSQL Data

40

Page 40: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Data De-normalization per interaction

41

ERP Product CatalogsCRM Data LakeData

Warehouse

Page 41: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Graph Data Persistence: Entities & Connections

•  Entities – Objects / Documents representing an Entity

•  Collections –  Logical grouping of Entities

•  Connections / Entity Relationships – Graph Data Structure –  /{collection}/{entityA}/{verb}/{collection}/

{entityB} –  /Users/me/likes/Products/iPhone6 –  /Recipes/Bread/includes/Ingredients/Flour

42

User A

Product A

User B

User C

Likes>> <<Liking

Page 42: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

Roadmap

43

Page 43: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

What’s Next for Usergrid

• Grow the community! • Blueprints Driver Release! • Service abstraction •  Indexing closer to real-time • Larger Clusters • Distributed Work System • Encryption & Security

44

Page 44: I Love APIs 2015: Apache Usergrid Web Scale Mobile APIs with Elastic Search and Cassandra

http://usergrid.apache.org

45