(SQL Server) Nosql
Total Page:16
File Type:pdf, Size:1020Kb
Relational to NoSQL: Getting started from SQL Server Shane Johnson Sr. Product Marketing Manager Couchbase Today’s agenda § Why NoSQL? § Identifying the right application § Modeling your data § Accessing your data § Installing and scaling your database § Monitoring and managing your deployment § Q & A ©2015 Couchbase Inc. 2 About the speakers – Shane Johnson Shane Johnson Senior Product Marketing Manager Couchbase (since Dec 2013) Experience: - Proud Red Hatter - Consulting (Architect) - Transitioned to Marketing (Technical Manager) - Passionate about Open Source - Expertise - Java and Distributed Systems ©2015 Couchbase Inc. 3 What’s Couchbase? Couchbase is the company behind Couchbase Server & Couchbase Mobile • Open source JSON database • Founded 2010 • 500+ enterprise customers globally Some of our customers: Couchbase Server can be deployed as: Document database Key-value store Distributed cache ©2015 Couchbase Inc. 4 What is NoSQL? § No SQL? No. § Distributed (most) § Not only SQL? Not really. – Scaled out, not up § Non relational? Yes. • Elasticity and commodity hardware – Partitioned and replicated • Scalability, performance, availability § Schema-less (most) – Flexible model – JSON (some) ©2015 Couchbase Inc. 5 Who is using NoSQL? Enterprises are adopting NoSQL for mission critical applications Media & Publishing eCommerce Hospitality ©2015 Couchbase Inc. 6 Who is using NoSQL? § Gannett, publisher of USA Today and 90+ media properties, replaced relational database tech- nology with NoSQL to power its digital publishing platform. § Marriott deployed NoSQL to modernize its hotel reservation system that supports $38 billion in annual bookings. § FHLBank Topeka leverages NoSQL on top of SQL Server to speed up access to customer financial data for its 770 member banks § Cars.com, with over 30 million visits per month, replaced SQL Server with NoSQL to store customer and vehicle data § Vente-privee.com improved the customer experience of its 18 million members by replacing SQL Server with NoSQL for better performance ©2015 Couchbase Inc. 7 Why are they using NoSQL? Technology Drivers Technical Needs § Customers are going online § Develop with agility § The Internet is connecting everything – Flexibility + Simplicity § Big Data is getting bigger – Easier + Faster § Applications are moving to the cloud § Operate at any scale § The world has gone mobile – Elasticity + Availability – Performance at scale – Always-on, global deployment Business Needs § Innovate and compete – Faster time to market – Reduced costs (operational + hardware) ©2015 Couchbase Inc. 8 – Increased revenue Why migrate from SQL Server? § Easier to scale 3 nodes to 100s, 1 data center to many, commodity hardware § Better performance integrated caching, memory-optimized indexes, memory-based replication § Up to 40x lower cost open source, subscription-based, per instance (not per core) § Cross-platform runs on Windows or Linux (Red Hat, Ubuntu, Debian, etc) § Greater agility JSON-based data model, SQL-based query language ©2015 Couchbase Inc. 9 How do you get started? § Identify the right application § Model your data § Access your data § Install and scale your database § Monitor and manage your deployment ©2015 Couchbase Inc. 10 Identifying the right application Have one or more of the following characteristics or requirements: Iterate faster Supports users anywhere and Send and receive JSON everywhere Provide low latency at any throughput Be available 24x7 Support many concurrent users Store terabytes of data Read and write to multiple data centers Examples: Application § High performance, high availability caching service § Small, independent application with a narrow scope § Logical or physical service within a large application Service Service Service § Global service that powers multiple applications RDMBS NoSQL ©2015 Couchbase Inc. 11 Concepts: Terminology Relational (SQL Server) NoSQL (Couchbase) Failover Cluster Cluster Availability Group Cluster Database Bucket Table Bucket Row (Tuple) Document (JSON) Primary Key Object ID IDENTITY Counter Indexed View View SQL N1QL ©2015 Couchbase Inc. 12 Model your data ©2015 Couchbase Inc. 13 Modeling your data: Fixed vs. self-describing schema ©2015 Couchbase Inc. 14 Modeling your data: The flexibility of JSON Same document type, Different fields • Different types • Optional • On-demand Tip: Add a version field to track changes. {“docType”: “user”, “docVersion”: “1”, …} {“docType”: “user”, “docVersion”: “2”, …} ©2015 Couchbase Inc. 15 Modeling your data: Changing the data model Relational database Document database • Modify the database schema • Modify the interface (e.g. HTML5/JS) • Modify the application code (e.g. Java) • Modify the interface (e.g. HTML5/JS) ©2015 Couchbase Inc. 16 Modeling your data: Object IDs Best Practices Examples • Natural Keys • author::shane • Human Readable • author::shane::blogs • Deterministic • blog::nosql_fueled_hadoop • Semantic • blog::nosql_fueled_hadoop::comments What about identity columns? 1. Document<Long> nextAuthorIdDoc= bucket.counter(“authorIdCounter”, 1); 2. Long nextAuthorId = nextAuthorIdDoc.content(); 3. String authDocId = “author::” + nextAuthorId; // author::101 Tip: Increment the counter by 10, 20, etc. instead of doing it for every insert. ©2015 Couchbase Inc. 17 Modeling your data: Relationships Bottom up Top down Author Author (FK x2) Blog (FK) Blog (FK) Blog (FK x2) Blog Comment (FK) Comment (FK) Comment Comment ©2015 Couchbase Inc. 18 Modeling your data: Relationships ©2015 Couchbase Inc. 19 Modeling your data: Strategies and best practices 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 ©2015 Couchbase Inc. 20 Modeling your data: Strategies and best practices § Are they a lot of concurrent writes, continuous updates? § Store children as separate documents Blog Blog Thread § Thread § { { Comment “docType”: “blog”, “docType”: “thread”, § Comment “author”: “author::shane”, “comments”: [ § Thread “title”: “Couchbase Wins”, { § Comment “threads”: [ “visitor”: “Brendan Bond”, § Comment “blog::couchbase_wins::threads::001”, “text”: “This blog is amazing!” “blog::couchbase_wins::threads::002” “replies”: [ } { “user”: “Dustin Johnson”, “text”: “No, it is not.” }] } ©2015 Couchbase Inc. } 21 Access your data ©2015 Couchbase Inc. 22 Accessing your data: Options We’ll focus on these three for now. Key-Value N1QL Views Full Text Geospatial (CRUD) (Query) (Query) (Search) (Search) Indexes MapReduce Indexes MapReduce Documents ©2015 Couchbase Inc. 23 Accessing your data: Connecting to the database § Access data via topology-aware smart clients § Maintains an up-to-date cluster map § Communicates directly with database nodes – no proxies, no routers, etc. § Available for Java, Node.js, PHP, .NET, Python, C, Go, and more § With standard, certified JDBC/ODBC drivers (if you want to) ©2015 Couchbase Inc. 24 Accessing your data: Domain objects vs. document objects Working with document objects requires less code, provides more flexibility. * JSON serialization via Boon. ©2015 Couchbase Inc. 25 Accessing your data: Key-value operations – referenced data ©2015 Couchbase Inc. 26 Accessing your data: Key-value operations – nested data ©2015 Couchbase Inc. 27 Accessing your data: Subdocument operations ©2015 Couchbase Inc. 28 Accessing your data – N1QL queries: Capabilities Feature SQL N1QL JOIN ✔ ✔ TRANSFORM ✔ ✔ FILTER ✔ ✔ AGGREGATE ✔ ✔ SORT ✔ ✔ SUBQUERIES ✔ ✔ PAGINATION ✔ ✔ OPERATORS ✔ ✔ FUNCTIONS ✔ ✔ ©2015 Couchbase Inc. 29 Accessing your data: N1QL queries – referenced data ©2015 Couchbase Inc. 30 Accessing your data: N1QL queries – nested data ©2015 Couchbase Inc. 31 Accessing your data: N1QL queries – CRUD ©2015 Couchbase Inc. 32 Accessing your data: LINQ _context.Query<Users>().Where(u => u.status == “Platinum”) from user in _context.Query<Users>() join account in _context.Query<Account>() on user.accountIdequals N1QlFunctions.Key(account) into userGroup from accounts in userGroup.DefaultIfEmpty() where (account.type == “Visa” || account.type== “MasterCard”) select new { firstName = user.firstName, lastName = user.LastName }; from user in _context.Query<Users>() join address in _context.Query<Address>() on user.addresses.shipping.addressId equals N1QlFunctions.Key(address) into addressGroup from address in addressGroup.DefaultIfEmpty() where address.state == “CA” select new { firstName = user.firstName, lastName = user.LastName }; ©2015 Couchbase Inc. 33 Accessing your data: N1QL queries – indexes Simple Functional Compound Partial ©2015 Couchbase Inc. 34 Accessing your data: Views What if indexed views worked great with write intensive workloads? And you could use COUNT, ORDER BY, and everything else… ©2015 Couchbase Inc. 35 Accessing your data: Views COUNT ?!? ©2015 Couchbase Inc. 36 Accessing your data: Views – Incremental MapReduce ©2015 Couchbase Inc. 37 Accessing your data: Views – queries ©2015 Couchbase Inc. 38 Accessing your data: Strategies and best practices Concept Strategies & Best Practices Key Value Operations provide the best • Create an effective key naming strategy possible performance • Create an optimized data