document data modelling with couchbase server 4.0
TRANSCRIPT
Data Modelingwith Couchbase Server
4.0Cihan Biyikoglu | Dir. Product Management,
Couchbase
©2015 Couchbase Inc. 2
Agenda• What is Data Modeling?• Couchbase Server Data Models• Documents with JSON and Key-Values
• Phase I - Logical data modeling• Entitles, Attributes and Relationships
• Phase II - Physical data modeling• Keys, Documents/Values, Attributes and Buckets• Relationships
• Evolving Data Models• Q&A
©2015 Couchbase Inc. 3
What is Data Modeling? Data Modeling:
Exploring Structure of Data that best fit your apps needs
Modeling Cities: Buildings, ports, roads and moreModeling Investments: Instruments, investors, orders and moreModeling Travel Documents: Airlines, hotels, rental cars, travellers and more
©2015 Couchbase Inc. 4
Couchbase Server Data Models
©2015 Couchbase Inc. 5
Couchbase Server Data Models Documents with JSON
– Represent complex entities with full modeling and query flexibility
Ex: purchase order, travel itinerary
{ “Name”: “Pike Brewing”, “Addresses”: [
{ “Loc_Identifier”:”HQ”,“Street”:”1 pike
place market st”,“City”: “Seattle”…},{
“Loc_Identifier”:”Bellevue”,…}
], “Founders”:… “EstablishedData”:… …}
Brewery_Pike_Brewing
Key-Value– Represent simple entities
with fast & direct accessEx: passwords, session-state, private/public keys
0xAB635FF987234789BC987D987EE897723498765
pwd_userid_00001Key
Value
©2015 Couchbase Inc. 6
Logical Data Model
©2015 Couchbase Inc. 7
Logical Data Modeling Phase I – define entities, attributes and their relationships
– Entities: Main objects that are targets of your apps operates on• Attributes: properties that your applications keep track of for the
entity• Relationships: definition connections to other entities - 1-1, 1-
many, many-many
Satellites
Instruments
Measurements
Missions
Manufacturers
©2015 Couchbase Inc. 8
Physical Data Model
©2015 Couchbase Inc. 9
Physical Data Model Phase II – Map entities, attributes and their relationships to
containers provided by the underlying database solution
Relational Databases Couchbase ServerDatabases Buckets
Tables Documents with type designator attribute OR
Buckets
Rows Items (Key-Value or Key-Document)
Columns Attributes
Index Index
©2015 Couchbase Inc. 10
Physical Data Modeling Entities > Buckets, Keys & Items
– Buckets: group of items with controls for HA, Security and Computational Resources• Replica count, compaction schedule, RAM quota and more
– Keys: unique identifier for instances of the entity• Composite or Surrogate
– Items• JSON Documents with Attributes:
Basic types: bool, string, numeric, date or array of these types Embedded JSON Documents or array of embedded of these types
• Binary Values: Anything up to 20MB
©2015 Couchbase Inc. 11
Remember our logical data modeling?
Satellites
Instruments
Measurements
Missions
Manufacturers
©2015 Couchbase Inc. 12
Physical Data Modeling Physical Data Model
Satellites{ “name”:…, “route”:…, “missions”:[ {“name”:“launch”, “date”:…,}, {“name”:”repair-1”, “date”:…,} …], “instruments”:[ {“id”:“camera_01”}, {“id”:”altimeter_01”}, …], “manufacturer”:{ “name”:”Boeing”, “city”:”Seattle”,…}, …}
Instruments{ “id”:”camera_01”, “manufacturer”:{ “name”:”Boeing”, “city”:”Seattle”,…},…}
Inst
rum
ent I
Ds Measurements{ “instrument_ id”:”altimeter_01”, “satellite_name”:…, “date_time”:…, “location”:{ “lat”:…,“long”:…}, “measurement”:……}M
anuf
actu
rer
Miss
ions
©2015 Couchbase Inc. 13
Embedding vs Referencing Embed When
– Both docs are frequently access together.
– You need strict consistency between both docs.
Reference When– Both docs aren’t frequently
access together.– You need strict consistency
for the referenced information– Need to optimize for
performance and referenced doc is large
©2015 Couchbase Inc. 14
References: SQL JOINs with Couchbase Server 4.0
Note: References are flexible in N1QL
SELECT AVG(m.measurement),…FROM Measurements m
JOIN Satellites sON KEYS
m.satellite_nameWHERE m.date_time BETWEEN … AND NOW();
©2015 Couchbase Inc. 15
Relationships 1-1
– Embed Example: Satellite and Manufacturer 1-Many
– Embed Example: Satellite and Missions– Reference Example: Satellite and Instruments
Many-Many– Reference Example: Satellite and Measurements
©2015 Couchbase Inc. 16
Evolving Data Models
©2015 Couchbase Inc. 17
Evolving Data ModelsChange your apps code and you are good to go!
Schema is App Driven in Couchbase Server– OK to maintain multiple versions of the schema
Schema Changes with Couchbase Server– No Explicit Server Action Required by DBA– No Downtime required to update existing data to new shape
©2015 Couchbase Inc. 18
Recap Couchbase Server support key-value and document based
data modeling natively. Model data in 2 phases
– Logical data model– Physical data model• Embed vs Reference
Evolve your Schema without pain
Get Started with Couchbase Server 4.0 - Couchbase.com/Downloads
Q&ACihan Biyikoglu | [email protected] |
@cihangirb