app engine engine...query sql like query full support of sql language flexibility-like query...

57
App Engine: Datastore Introduction Part 1 Another very useful course: https://www.udacity.com/course/developing-scalable- apps-in-java--ud859 1

Upload: others

Post on 15-Jul-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

App Engine: Datastore Introduction

Part 1

Another very useful course:https://www.udacity.com/course/developing-scalable-apps-in-java--ud859

1

Page 2: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Topics cover in this lessonTopics cover in this lesson

• What is Datastore?What is Datastore?– Datastore and relational database– Scalability, reliability and performancey, y p

• Datastore Internals– BigtableBigtable

• Datastore Basics Operation– Entity Properties and KeysEntity, Properties and Keys– Properties and Value Types– Datastore APIsDatastore APIs

2

Page 3: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

What is Datastore?What is Datastore?

• Datastore is a database (persistent storage)Datastore is a database (persistent storage) for AppEngine

AppEngine Traditional Web Apps

Web application

AppEngine(Java, Python,

Pert/CGIPHP

framework PHP, Go) Ruby on RailsPersistent storage

Datastore RDBMS: MySQL MSstorage MySQL, MS SQL, Oracle

3

Page 4: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

What is Datastore?

• Persistent storage for AppEngine

What is Datastore?

Persistent storage for AppEngine• AppEngine is very scalable=> Many instances

=> Central Server to store data from all=> Central Server to store data from all instances.Wh RDB? S l bili !• Why not RDB? Scalability!

4

Page 5: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Datastore and RDBMSDatastore and RDBMS

Datastore RDBMSDatastore RDBMS

Query SQL like query Full support of SQLQuery language flexibility

SQL-like query language : Limited to simple filter and

Full support of SQL-Table JOIN- Flexible filtering

sort - SubqueryReliability and S l bilit

Highly scalable and li bl ith

Hard to scaleScalability reliable with

performance

D t t ff G l l l l bilit

5

Datastore offsers Google-level scalability

Page 6: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Problems of Scalability and ReliabilityProblems of Scalability and Reliability

• Single InstanceSingle Instance– Performance limited by machine resource

Single point of failure– Single point of failure

• Replication (copies) increases reliability– Consistency among instances

• Sharding (Split among machines)– Lock control (transaction)[Shard = split server into multiple machines]

6

Page 7: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Strong Consistency and Eventual Consistency

Strong Data is always consistent among allStrong Consistency

Data is always consistent among all database instances-Just after write operation- Crash in the middle of write operation -> All server returns the same results.

Eventual Takes time until all data becomesEventual Consistency

Takes time until all data becomesconsistent after write(Think of DNS as an example)

DNS i di t ib t d d t b tDNS is a distributed database system.Updated configuration on domain -> Not reflected to all DNS immediately. For a certain period of time, some DNS servers return old. 7

Page 8: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Scalability, Reliability and Performance on RDB

• Replication and/or sharding for scalabilityReplication and/or sharding for scalability• But…

St i t RDB l it ti– Strong consistency on RDB slows write operations due to lock.Join operation is a bottleneck due to data– Join operation is a bottleneck due to data shuffling.

RDB ensures strong consistency -> Hard to ensure scalability.

8Datastore for AppEngine

Page 9: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Datastore InternalsDatastore Internals• Based on Bigtable, which offers super high

l biliscalability.• High availability by High Replication Datastore

(HRD)– Synchronous write on multiple datacenters.

• Supports strong consistency among multiple rows

9

Page 10: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

What is Bigtable?What is Bigtable?

• Scalable, distributed, highly-available and Sca ab e, d st buted, g y a a ab e a dstructured storage– Bigtable is not database itself (it doesn’t support

query)• Consistency

S i f i l– Strong consistency for single row– Eventual consistency for multi-row level

• Google usage• Google usage– In production since April 2005– Web search youtubeWeb search, youtube…

10

Page 11: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Automatic Scale-out of Bigtable table server

11

Page 12: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Bigtable Data ModelBigtable Data Model

• Key value data storageKey value data storage• A row has a Key and Columns

S d b• Sorted by Key– In lexical order– Enables range query by application

12

Page 13: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Bigtable OperationsBigtable Operations

• CRUD on a rowCRUD on a row– Create, Read, Update and Delete operations

Preserves single row strong consistency (not– Preserves single-row strong consistency (not multiple row).

• Scan by range of keys• Scan by range of keys– But can not search by column values

13

Page 14: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Scalability is based on Bigtable automated sharding

14

Scalability is based on Bigtable automated sharding.Megastore supports transactions (strong consistency)

Page 15: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

15Property = actual data you want to store

Page 16: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

16

Page 17: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

17Property can have multiple values. (Multiple data for one property)

Page 18: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

18

Page 19: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

19

Page 20: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

20

Page 21: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

App Engine: Datastore Query, Index andDatastore Query, Index and

Transactions

Part 2

21

Page 22: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

2222

Page 23: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

2323

Page 24: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

2424

Page 25: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

2525

Page 26: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

Bigtable can scanon a key, noton a key, not value!

Index table on Bigtable:Property name and valueImplement query on bigtable(without reading

t l l )actual value)

2626

Page 27: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

2727

Page 28: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

2828

Page 29: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

2929

Page 30: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3030

Page 31: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3131

Page 32: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3232

Page 33: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3333

Page 34: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3434

Page 35: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3535

Page 36: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3636

Page 37: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3737

Page 38: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3838

Page 39: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

3939

Page 40: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4040

Page 41: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4141

Page 42: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4242

Page 43: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4343

Page 44: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4444

Page 45: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4545

Page 46: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4646

Page 47: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4747

Page 48: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4848

Caveats = limitations

Page 49: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

4949

Page 50: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

5050

Page 51: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

5151

Page 52: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

5252

Page 53: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

5353

Page 54: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

5454

Page 55: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

5555

Page 56: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

5656

Page 57: App Engine Engine...Query SQL like query Full support of SQL language flexibility-like query language : Limited to simple filter and Full support of SQL-Table JOIN - Flexible filtering

57