Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved.
April 2022
Matthew D. Groves | Product Marketing Manager
JSON Data Modeling
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 2
Modeling Data in a Relational World
RDBMS table-based modeling
Billing
Connections
Purchases
Contacts
Customer
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved.
01/
02/
03/
04/
05/
Why NoSQL?
JSON Data Modeling
Accessing Data
Migrating Data
Summary / Q&A
Agenda
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 4
1 Why NoSQL?
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 5
NoSQL Landscape
• Couchbase
• DynamoDB
• CosmosDB
• Redis
• Aerospike
• Couchbase
• MongoDB
• DynamoDB
• CosmosDB
Key-Value Document
• Cassandra
• Hbase
• CosmosDB
• Datastax
• Neo4J
• OrientDB
• CosmosDB
Wide Column Graph
🔑 📄 🔢 🗺
Broad categories, many are "multi-model"
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 6
NoSQL Landscape
• Couchbase
• MongoDB
• DynamoDB
• CosmosDB
Document
📄
Broad categories, many are "multi-model"
• Store data as JSON (or XML, etc)
• Get by key
• Set by key
• Replace by key
• Delete by key
• Query/index
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 7
What's NoSQL?
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 8
Why NoSQL? Scalability
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 9
Why NoSQL? Flexibility
{
"name" : "matt groves"
}
{
"firstName" : "jeff",
"lastName" : "morris"
}
DocumentKey: 120902
DocumentKey: 930912
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 10
Why NoSQL? Availability
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 11
Why NoSQL? Fast
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 12
Use Cases for NoSQL
• Caching
• Session
• User profile
• Catalog
• Content management
• Personalization
• Customer 360
• IoT
• Inventory
• Communication
• Gaming
• Advertising
• Travel booking
• Loyalty programs
• Fraud monitoring
• Social media
• Finance
• Health Care
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 13
Use Cases
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 14
2 JSON Data Modeling
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 15
Properties of Real-World Data
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 16
Modeling Data in a Relational World
RDBMS table-based modeling
Billing
Connections
Purchases
Contacts
Customer
CustomerID Name DOB
CBL2015 Jane
Smith
1990-01-30
Table: Customer
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30”
}
Customer Document
Key: CBL2015
©2017 Couchbase Inc. 18
CustomerID Name DOB
CBL2015 Jane
Smith
1990-01-30
Table: Customer
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Purchases" : [
{
"item" : "laptop",
"amount" : 1499.99,
"date" : "2019-03",
}
]
}
Customer Document
Key: CBL2015
CustomerID Item Amount Date
CBL2015 laptop 1499.99 2019-03
Table: Purchases
CustomerID Name DOB
CBL2015 Jane
Smith
1990-01-30
Table: Customer
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Purchases" : [
{
"item" : "laptop",
"amount" : 1499.99,
"date" : "2019-03",
},
{
"item" : "phone",
"amount" : 99.99,
"date" : "2018-12"
}
]
}
Customer Document
Key: CBL2015
CustomerID Item Amount Date
CBL2015 laptop 1499.99 2019-03
CBL2015 phone 99.99 2018-12
Table: Purchases
CustomerID ConnId Relation
CBL2015 XYZ987 Brother
CBL2015 SKR007 Father
Table: Connections
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Billing" : [
{
"type" : "visa",
"cardnum" : "5827-2842-...",
"expiry" : "2019-03"
}, ...
],
"Connections" : [
{
"ConnId" : "XYZ987",
"Relation" : "Brother"
},
{
"ConnId" : "SKR007",
"Relation" : "Father"
}
}
Customer Document
Key: CBL2015
©2017 Couchbase Inc. 21
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"cardnum" : "5827-2842…",
"expiry" : "2019-03",
"cardType" : "visa",
"Connections" : [
{
"CustId" : "XYZ987",
"Relation" : "Brother"
},
{
"CustId" : "SKR007",
"Relation" : "Father"
}
],
"Purchases" : [
{ "id":12, item: "mac", "amt": 2823.52 }
{ "id":19, item: "ipad2", "amt": 623.52 }
]
}
Customer Document
Key: CBL2015
CustomerID Name DOB Cardnum Expiry CardType
CBL2015 Jane
Smith
1990-01-30 5827-2842… 2019-03 visa
CustomerID ConnId Relation
CBL2015 XYZ987 Brother
CBL2015 SKR007 Father
CustomerID item amt
CBL2015 mac 2823.52
CBL2015 ipad2 623.52
CustomerID ConnId Name
CBL2015 XYZ987 Joe
Smith
CBL2015 SKR007 Sam
Smith
Contacts
Customer
Connections
Purchases
{
"Name" : "Bob Jones",
"DOB" : "1980-01-29",
"Billing" : [
{
"type" : "visa",
"cardnum" : "5927-2842-2847-3909",
"expiry" : "2020-03"
},
{
"type" : "master",
"cardnum" : "6273-2842-2847-3909",
"expiry" : "2019-11"
}
],
"Connections" : [
{
"CustId" : "XYZ987",
"Relation" : "Brother"
},
{
"CustId" : "PQR823",
"Relation" : "Father"
}
],
"Purchases" : [
{ "id":12, item: "mac", "amt": 2823.52 },
{ "id":19, item: "ipad2", "amt": 623.52 }
]
}
Customer Document
Key: CBL2016
CustomerID Name DOB
CBL2016 Bob Jones 1980-01-29
CustomerID Type Cardnum Expiry
CBL2016 visa 5927… 2020-03
CBL2016 master 6273… 2019-11
CustomerID ConnId Relation
CBL2016 XYZ987 Brother
CBL2016 SKR007 Father
CustomerID item amt
CBL2016 mac 2823.52
CBL2016 ipad2 623.52
CustomerID ConnI
d
Name
CBL2016 XYZ987 Joe
Smith
CBL2016 SKR007 Sam
Smith
Contacts
Customer
Billing
Connections
Purchases
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 23
Versioning approach 1: Version Numbers
{
"name" : "matt groves"
"version" : 1
}
{
"firstName" : "jeff",
"lastName" : "morris",
"version" : 2
}
Document Key:
120902
Document Key:
930912
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 24
Versioning approach 2: Big Bang Re-versioning
{
"name" : "matt groves"
}
{
"firstName" : "matt",
"lastName" : "groves
}
Document Key:
120902
Document Key:
120902
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 25
Versioning approach 3: Cooperative Re-versioning
{
"name" : "matt groves"
}
{
"firstName" : "matt",
"lastName" : "groves",
}
DocumentKey: 120902
DocumentKey: 120902
Web application
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 26
Modeling tools
• Hackolade
• Erwin DM NoSQL
• https://jsoneditoronline.org
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 27
3 Accessing Data
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 28
Key/Value
public async Task<ShoppingCart> GetCartById(string id)
{
var cart = await _collection.GetAsync(id);
return cart.ContentAs<ShoppingCart>();
}
public async Task CreateShoppingCart()
{
await _collection.InsertAsync(
Guid.NewGuid().ToString(),
new ShoppingCart { . . . }
);
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 29
Key/Value: Recommendations for keys
• Natural Keys
• Account number, driver license number, ISBN
• Human Readable
• "user-123" vs "0be12ae9-1b1d-4724-9706-2977cc134daf"
• Deterministic
• "matt" -> "matt::blogs" -> "blog::csharp_9_features"
• Semantic
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 30
Key/Value: Example keys
1. User logs in with username and password
• Lookup "author::<username>" in the database
2. Once logged in, save username to session state.
3. User wants to view their blogs.
• Lookup "author::<username>::blogs" in the database
4. Document contains list of "slugs"
5. User wants to view a specific blog.
• Lookup "blog::<slug>" in the database
6. User wants to view all comments for this post
• Lookup "blog::<slug>::comments" in the database
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 31
Modeling your data: Strategies / rules of thumb
• Relationship is one-to-one or one-
to-many
• Store related data as nested
objects
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Purchases" : [
{
"item" : "laptop",
"amount" : 1499.99,
"date" : "2019-03",
},
{
"item" : "phone",
"amount" : 99.99,
"date" : "2018-12"
}
]
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 32
Modeling your data: Strategies / rules of thumb
• Relationship is many-to-one or
many-to-many
• Store related data as separate
documents
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Connections" : [
"XYZ987",
"PQR823",
"PQR828"
]
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 33
Modeling your data: Strategies / rules of thumb
• Data reads are mostly parent fields
• Store children as separate
documents
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Connections" : [
"XYZ987",
"PQR823",
"PQR828"
]
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 34
Modeling your data: Strategies / rules of thumb
• Data reads are mostly parent +
child fields
• Store children as nested objects
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Purchases" : [
{
"item" : "laptop",
"amount" : 1499.99,
"date" : "2019-03",
},
{
"item" : "phone",
"amount" : 99.99,
"date" : "2018-12"
}
]
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 35
Modeling your data: Strategies / rules of thumb
• Data writes are mostly parent or
child (not both)
• Store children as separate
documents
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Connections" : [
"XYZ987",
"PQR823",
"PQR828"
]
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 36
Modeling your data: Strategies / rules of thumb
• Data writes are mostly parent and
child (both)
• Store children as nested objects
{
"Name" : "Jane Smith",
"DOB" : "1990-01-30",
"Purchases" : [
{
"item" : "laptop",
"amount" : 1499.99,
"date" : "2019-03",
},
{
"item" : "phone",
"amount" : 99.99,
"date" : "2018-12"
}
]
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 37
Modeling your data: Strategies / rules of thumb
If … Then …
Relationship is one-to-one or one-to-many Store related data as nested objects
Relationship is many-to-one or many-to-many Store related data as separate documents
Data reads are mostly parent fields Store children as separate documents
Data reads are mostly parent + child fields Store children as nested objects
Data writes are mostly parent or child (not
both)
Store children as separate documents
Data writes are mostly parent and child (both) Store children as nested objects
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 38
Subdocument access
{
"username": "mgroves",
"profile": {
"phoneNumber": "123-456-7890",
"address": {
"street": "123 main st",
"city": "Grove City",
"state": "Ohio"
}
}
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 39
Other ways to access data (Couchbase)
Key-Value
(CRUD)
SQL++
(SQL Query)
Full Text
(Search)
Documents
Indexes Indexes
Mobile
(iOS/
Android)
Analytics
(Query)
Sync
Gateway
SQL++
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 40
SQL++
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 41
Understanding your Query Plan
"recommended_indexes": {
"indexes": [{
"index_statement":
"CREATE INDEX adv_name ON `default`:`travel-sample`.`inventory`.`airline`(`name`)",
"keyspace_alias": "airline_a",
"recommending_rule": "Index keys follow order of predicate types: 8. like."
}]
}
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 42
Full Text Search
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 43
Accessing your data
Strategies and recommendations
Concept Strategies & Recommendations
Key-Value Operations provide the best
possible performance
• Create an effective key naming strategy
• Create an optimized data model
Full Text Search is well-suited to text • Facets / ranges / geography
• Language aware
• Inverted index
N1QL queries provide the most flexibility –
everything else
• Query data regardless of how it is modeled
• Good indexing is vital
• B-Tree
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 44
4 Migrating Data
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 45
How do you migrate?
A spectrum of approaches
1. Rewrite: No migration, write the whole thing over
2. Redesign Schema: Keep your business logic, rewrite your data
layer and schema, totally redesign your schema with a NoSQL-
optimized model
3. Refactor First: Keep everything but refactor your data logic
and RDBMS schema into a NoSQL-optimized model
4. Optimize Later: Host your schema with as few changes as
possible, get the application running on the new technology,
refactor/optimize the schema as necessary for performance
5. Just Host It: Host your schema with as few changes as
possible.
Risk
Effort
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 46
Migration options
Tools
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 47
Migration options
Build Your Own (BYO)
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 48
Migration options: KISS (level 5)
"Level 5" = "Just Host it"
Export
Transform
Import
NoSQL (optimized)
Relational
NoSQL
(raw)
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 49
Migration options
KISS (levels 4,3,2)
Export
Transform
Import
NoSQL
Relational
NoSQL (optimized)
"staging"
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 50
Migration Recommendations
Alignment
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 51
SqlServerToCouchbase Demo
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 52
5 Summary
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved.
Pick the right
application
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved.
Proof of Concept
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved.
Match the data
access method to
requirements
Confidential and Proprietary. Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 56
Next Steps
• Couchbase playground:
• https://couchbase.live
• Couchbase Capella free trial:
• https://cloud.couchbase.com/sign-up
• SqlServerToCouchbase:
• https://github.com/mgroves/SqlServerToCouchbase

JSON Data Modeling in Document Database

  • 1.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. April 2022 Matthew D. Groves | Product Marketing Manager JSON Data Modeling
  • 2.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 2 Modeling Data in a Relational World RDBMS table-based modeling Billing Connections Purchases Contacts Customer
  • 3.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 01/ 02/ 03/ 04/ 05/ Why NoSQL? JSON Data Modeling Accessing Data Migrating Data Summary / Q&A Agenda
  • 4.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 4 1 Why NoSQL?
  • 5.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 5 NoSQL Landscape • Couchbase • DynamoDB • CosmosDB • Redis • Aerospike • Couchbase • MongoDB • DynamoDB • CosmosDB Key-Value Document • Cassandra • Hbase • CosmosDB • Datastax • Neo4J • OrientDB • CosmosDB Wide Column Graph 🔑 📄 🔢 🗺 Broad categories, many are "multi-model"
  • 6.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 6 NoSQL Landscape • Couchbase • MongoDB • DynamoDB • CosmosDB Document 📄 Broad categories, many are "multi-model" • Store data as JSON (or XML, etc) • Get by key • Set by key • Replace by key • Delete by key • Query/index
  • 7.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 7 What's NoSQL?
  • 8.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 8 Why NoSQL? Scalability
  • 9.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 9 Why NoSQL? Flexibility { "name" : "matt groves" } { "firstName" : "jeff", "lastName" : "morris" } DocumentKey: 120902 DocumentKey: 930912
  • 10.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 10 Why NoSQL? Availability
  • 11.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 11 Why NoSQL? Fast
  • 12.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 12 Use Cases for NoSQL • Caching • Session • User profile • Catalog • Content management • Personalization • Customer 360 • IoT • Inventory • Communication • Gaming • Advertising • Travel booking • Loyalty programs • Fraud monitoring • Social media • Finance • Health Care
  • 13.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 13 Use Cases
  • 14.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 14 2 JSON Data Modeling
  • 15.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 15 Properties of Real-World Data
  • 16.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 16 Modeling Data in a Relational World RDBMS table-based modeling Billing Connections Purchases Contacts Customer
  • 17.
    CustomerID Name DOB CBL2015Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30” } Customer Document Key: CBL2015
  • 18.
    ©2017 Couchbase Inc.18 CustomerID Name DOB CBL2015 Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Purchases" : [ { "item" : "laptop", "amount" : 1499.99, "date" : "2019-03", } ] } Customer Document Key: CBL2015 CustomerID Item Amount Date CBL2015 laptop 1499.99 2019-03 Table: Purchases
  • 19.
    CustomerID Name DOB CBL2015Jane Smith 1990-01-30 Table: Customer { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Purchases" : [ { "item" : "laptop", "amount" : 1499.99, "date" : "2019-03", }, { "item" : "phone", "amount" : 99.99, "date" : "2018-12" } ] } Customer Document Key: CBL2015 CustomerID Item Amount Date CBL2015 laptop 1499.99 2019-03 CBL2015 phone 99.99 2018-12 Table: Purchases
  • 20.
    CustomerID ConnId Relation CBL2015XYZ987 Brother CBL2015 SKR007 Father Table: Connections { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Billing" : [ { "type" : "visa", "cardnum" : "5827-2842-...", "expiry" : "2019-03" }, ... ], "Connections" : [ { "ConnId" : "XYZ987", "Relation" : "Brother" }, { "ConnId" : "SKR007", "Relation" : "Father" } } Customer Document Key: CBL2015
  • 21.
    ©2017 Couchbase Inc.21 { "Name" : "Jane Smith", "DOB" : "1990-01-30", "cardnum" : "5827-2842…", "expiry" : "2019-03", "cardType" : "visa", "Connections" : [ { "CustId" : "XYZ987", "Relation" : "Brother" }, { "CustId" : "SKR007", "Relation" : "Father" } ], "Purchases" : [ { "id":12, item: "mac", "amt": 2823.52 } { "id":19, item: "ipad2", "amt": 623.52 } ] } Customer Document Key: CBL2015 CustomerID Name DOB Cardnum Expiry CardType CBL2015 Jane Smith 1990-01-30 5827-2842… 2019-03 visa CustomerID ConnId Relation CBL2015 XYZ987 Brother CBL2015 SKR007 Father CustomerID item amt CBL2015 mac 2823.52 CBL2015 ipad2 623.52 CustomerID ConnId Name CBL2015 XYZ987 Joe Smith CBL2015 SKR007 Sam Smith Contacts Customer Connections Purchases
  • 22.
    { "Name" : "BobJones", "DOB" : "1980-01-29", "Billing" : [ { "type" : "visa", "cardnum" : "5927-2842-2847-3909", "expiry" : "2020-03" }, { "type" : "master", "cardnum" : "6273-2842-2847-3909", "expiry" : "2019-11" } ], "Connections" : [ { "CustId" : "XYZ987", "Relation" : "Brother" }, { "CustId" : "PQR823", "Relation" : "Father" } ], "Purchases" : [ { "id":12, item: "mac", "amt": 2823.52 }, { "id":19, item: "ipad2", "amt": 623.52 } ] } Customer Document Key: CBL2016 CustomerID Name DOB CBL2016 Bob Jones 1980-01-29 CustomerID Type Cardnum Expiry CBL2016 visa 5927… 2020-03 CBL2016 master 6273… 2019-11 CustomerID ConnId Relation CBL2016 XYZ987 Brother CBL2016 SKR007 Father CustomerID item amt CBL2016 mac 2823.52 CBL2016 ipad2 623.52 CustomerID ConnI d Name CBL2016 XYZ987 Joe Smith CBL2016 SKR007 Sam Smith Contacts Customer Billing Connections Purchases
  • 23.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 23 Versioning approach 1: Version Numbers { "name" : "matt groves" "version" : 1 } { "firstName" : "jeff", "lastName" : "morris", "version" : 2 } Document Key: 120902 Document Key: 930912
  • 24.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 24 Versioning approach 2: Big Bang Re-versioning { "name" : "matt groves" } { "firstName" : "matt", "lastName" : "groves } Document Key: 120902 Document Key: 120902
  • 25.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 25 Versioning approach 3: Cooperative Re-versioning { "name" : "matt groves" } { "firstName" : "matt", "lastName" : "groves", } DocumentKey: 120902 DocumentKey: 120902 Web application
  • 26.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 26 Modeling tools • Hackolade • Erwin DM NoSQL • https://jsoneditoronline.org
  • 27.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 27 3 Accessing Data
  • 28.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 28 Key/Value public async Task<ShoppingCart> GetCartById(string id) { var cart = await _collection.GetAsync(id); return cart.ContentAs<ShoppingCart>(); } public async Task CreateShoppingCart() { await _collection.InsertAsync( Guid.NewGuid().ToString(), new ShoppingCart { . . . } ); }
  • 29.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 29 Key/Value: Recommendations for keys • Natural Keys • Account number, driver license number, ISBN • Human Readable • "user-123" vs "0be12ae9-1b1d-4724-9706-2977cc134daf" • Deterministic • "matt" -> "matt::blogs" -> "blog::csharp_9_features" • Semantic
  • 30.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 30 Key/Value: Example keys 1. User logs in with username and password • Lookup "author::<username>" in the database 2. Once logged in, save username to session state. 3. User wants to view their blogs. • Lookup "author::<username>::blogs" in the database 4. Document contains list of "slugs" 5. User wants to view a specific blog. • Lookup "blog::<slug>" in the database 6. User wants to view all comments for this post • Lookup "blog::<slug>::comments" in the database
  • 31.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 31 Modeling your data: Strategies / rules of thumb • Relationship is one-to-one or one- to-many • Store related data as nested objects { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Purchases" : [ { "item" : "laptop", "amount" : 1499.99, "date" : "2019-03", }, { "item" : "phone", "amount" : 99.99, "date" : "2018-12" } ] }
  • 32.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 32 Modeling your data: Strategies / rules of thumb • Relationship is many-to-one or many-to-many • Store related data as separate documents { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Connections" : [ "XYZ987", "PQR823", "PQR828" ] }
  • 33.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 33 Modeling your data: Strategies / rules of thumb • Data reads are mostly parent fields • Store children as separate documents { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Connections" : [ "XYZ987", "PQR823", "PQR828" ] }
  • 34.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 34 Modeling your data: Strategies / rules of thumb • Data reads are mostly parent + child fields • Store children as nested objects { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Purchases" : [ { "item" : "laptop", "amount" : 1499.99, "date" : "2019-03", }, { "item" : "phone", "amount" : 99.99, "date" : "2018-12" } ] }
  • 35.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 35 Modeling your data: Strategies / rules of thumb • Data writes are mostly parent or child (not both) • Store children as separate documents { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Connections" : [ "XYZ987", "PQR823", "PQR828" ] }
  • 36.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 36 Modeling your data: Strategies / rules of thumb • Data writes are mostly parent and child (both) • Store children as nested objects { "Name" : "Jane Smith", "DOB" : "1990-01-30", "Purchases" : [ { "item" : "laptop", "amount" : 1499.99, "date" : "2019-03", }, { "item" : "phone", "amount" : 99.99, "date" : "2018-12" } ] }
  • 37.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 37 Modeling your data: Strategies / rules of thumb If … Then … Relationship is one-to-one or one-to-many Store related data as nested objects Relationship is many-to-one or many-to-many Store related data as separate documents Data reads are mostly parent fields Store children as separate documents Data reads are mostly parent + child fields Store children as nested objects Data writes are mostly parent or child (not both) Store children as separate documents Data writes are mostly parent and child (both) Store children as nested objects
  • 38.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 38 Subdocument access { "username": "mgroves", "profile": { "phoneNumber": "123-456-7890", "address": { "street": "123 main st", "city": "Grove City", "state": "Ohio" } } }
  • 39.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 39 Other ways to access data (Couchbase) Key-Value (CRUD) SQL++ (SQL Query) Full Text (Search) Documents Indexes Indexes Mobile (iOS/ Android) Analytics (Query) Sync Gateway SQL++
  • 40.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 40 SQL++
  • 41.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 41 Understanding your Query Plan "recommended_indexes": { "indexes": [{ "index_statement": "CREATE INDEX adv_name ON `default`:`travel-sample`.`inventory`.`airline`(`name`)", "keyspace_alias": "airline_a", "recommending_rule": "Index keys follow order of predicate types: 8. like." }] }
  • 42.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 42 Full Text Search
  • 43.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 43 Accessing your data Strategies and recommendations Concept Strategies & Recommendations Key-Value Operations provide the best possible performance • Create an effective key naming strategy • Create an optimized data model Full Text Search is well-suited to text • Facets / ranges / geography • Language aware • Inverted index N1QL queries provide the most flexibility – everything else • Query data regardless of how it is modeled • Good indexing is vital • B-Tree
  • 44.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 44 4 Migrating Data
  • 45.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 45 How do you migrate? A spectrum of approaches 1. Rewrite: No migration, write the whole thing over 2. Redesign Schema: Keep your business logic, rewrite your data layer and schema, totally redesign your schema with a NoSQL- optimized model 3. Refactor First: Keep everything but refactor your data logic and RDBMS schema into a NoSQL-optimized model 4. Optimize Later: Host your schema with as few changes as possible, get the application running on the new technology, refactor/optimize the schema as necessary for performance 5. Just Host It: Host your schema with as few changes as possible. Risk Effort
  • 46.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 46 Migration options Tools
  • 47.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 47 Migration options Build Your Own (BYO)
  • 48.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 48 Migration options: KISS (level 5) "Level 5" = "Just Host it" Export Transform Import NoSQL (optimized) Relational NoSQL (raw)
  • 49.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 49 Migration options KISS (levels 4,3,2) Export Transform Import NoSQL Relational NoSQL (optimized) "staging"
  • 50.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 50 Migration Recommendations Alignment
  • 51.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 51 SqlServerToCouchbase Demo
  • 52.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 52 5 Summary
  • 53.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. Pick the right application
  • 54.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. Proof of Concept
  • 55.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. Match the data access method to requirements
  • 56.
    Confidential and Proprietary.Do not distribute without Couchbase consent. © Couchbase 2021. All rights reserved. 56 Next Steps • Couchbase playground: • https://couchbase.live • Couchbase Capella free trial: • https://cloud.couchbase.com/sign-up • SqlServerToCouchbase: • https://github.com/mgroves/SqlServerToCouchbase