Why No SQL wpCOUCHBASE2022
Why No SQL wpCOUCHBASE2022
Why NoSQL
Databases?
Why successful projects rely on
NoSQL database applications
What is NoSQL?
NoSQL is a modern database management system Relational vs. NoSQL: What’s the
that stores information in JSON documents instead of
difference?
the columns and rows used by relational databases.
Relational databases were born in the era of mainframes
It can deliver data for applications in ways that make
and back-office business applications – long before the
development easier and more robust.
internet, the cloud, big data, mobile, etc. In fact, the first
NoSQL databases are built from the ground up to be
commercial implementation was released by Oracle in
flexible, scalable, and capable of rapidly responding to the
1979. These databases were engineered to run on a single
data management demands of modern businesses.
server – the bigger, the better. The only way to increase
This paper introduces the modern challenges that NoSQL the capacity of these databases was to upgrade the
databases address and shows when to choose NoSQL over server – processors, memory, and storage – to scale up as
relational and why. Moore’s Law allowed.
WHITEPAPER 2
Supporting SQL
and NoSQL developers
Traditional relational systems manage tabular data and
return it as rows and columns. NoSQL databases can do
this without forcing application developers into using a
static schema that has to be reworked every time there is
a change. Instead, NoSQL databases give developers the
flexibility they need to help them excel at their work.
• Support large numbers of concurrent users (tens of • Ryanair, the world’s busiest airline uses NoSQL to
thousands, perhaps millions) power its mobile app serving over 3 million users
• Deliver highly responsive experiences to a globally • Marriott hosts 30 million documents, accessed at
distributed base of users 4,000 transactions per second
• Be always available – no downtime • GE deploys NoSQL for its Predix platform to help
manage the industrial internet
• Handle semi- and unstructured data
• Sky / Peacock deploys NoSQL to offer a seamless
• Rapidly adapt to changing requirements with
viewing experience during peak watching times
frequent updates and new features
WHITEPAPER 3
Today’s trends – tomorrow’s challenges
Today’s customer experience goals depend on tightly aligned technical integration more than ever before, but it must be able
to handle trends going forward or risk becoming outdated.
Some of the high-level technical goals include: • Effective data “plumbing” for real-time web applications
and low latency
• Consolidated platforms that work together efficiently
• Act as a service layer that pushes data as close
• Simplified system architectures that are easy to manage
to the customer as possible
Here are five trends that play into the advantages of NoSQL databases for addressing the challenges of building software.
Trends Requirements
The above requirements are extensive and challenge even the best systems to do even more with less. Today’s extreme
requirements can be loosely grouped into two categories that impact two different levels of end users:
WHITEPAPER 4
Develop with agility
WHITEPAPER 5
Flexibility for faster development
By comparison, a NoSQL document database fully supports agile development, because it is schema-less and does not
statically define how the data must be modeled. Instead, it defers to the applications and services, and thus to the developers
as to how data should be modeled. With NoSQL, the data model is defined by the application model. Applications and services
model data as objects.
The workaround is object-relational mapping (ORM) frameworks, which can be effective in simple scenarios, but can become
problematic in more complex situations.
Consider an application for managing resumes. It interacts with resumes as an object of user objects. It contains an array for
skills and a collection for positions. However, writing a resume to a relational database requires the application to “shred” the
user object.
WHITEPAPER 6
Storing this resume would require the application to insert six rows into three tables, as illustrated in Figure 3.
However, reading this profile would require the application to read six rows from three tables, as illustrated in Figure 4.
In contrast, a document-oriented NoSQL database reads and writes data formatted in JSON – which is the de facto
standard for consuming and producing data for web, mobile, and IoT applications. It not only can eliminate the
object-relational impedance mismatch, it can eliminate the overhead of ORM frameworks and simplifies application
development because objects are read and written without “shredding” them – i.e., a single object can be read or
written as a single document, as illustrated in Figure 5.
WHITEPAPER 7
Querying using SQL
Application developers that are used to querying with
SQL can continue to use the same language in NoSQL
platforms but operate against the JSON data that is
stored. For example, Couchbase provides a SQL-based
Grouping documents to ease access query standard known as SQL++ (sometimes known as
Unlike using predefined sets of schemas to differentiate N1QL) that returns results in JSON with sets of rows and
tables from one another, NoSQL databases have a subdocument components where appropriate. This is in
concept, such as buckets, that serve as a general holding contrast to the vast majority of other NoSQL databases
area for all documents. A database can have many (like MongoDB™) that don’t use SQL and require
logical, named, buckets for various purposes. The name is developers to climb a new language learning curve.
provided while connecting or requesting data and allows Standard statements are supported including SELECT
applications to have their own area in the system. … FROM … WHERE syntax. SQL++ also supports
Within those buckets are additional hierarchical logical aggregation, sorting, and joins (GROUP BY … SORT BY …
groupings that can be restricted to particular users LEFT OUTER/INNER JOIN). Querying collections, scopes,
or roles. These are called collections and/or scopes, and even nested arrays is supported. Query performance
allowing subsets of documents in a bucket to be named. can be improved with composite, partial, covering indexes,
Because this flexibility helps segregate data of one user and more.
or application from another, the developer does not have There are minimal changes for SQL experts to move to
to build their own security and reliability code, but can SQL++ where desired, with many basic queries working
instead let the underlying database do it. out of the box.
SQL SQL++
SELECT p.FirstName + ' ' + p.LastName AS SELECT p.FirstName || ' ' || p.LastName AS
Name, d.City Name, d.City
FROM AdventureWorks2016.Person.Person AS p FROM AdventureWorks2016.Person.Person AS p
INNER JOIN AdventureWorks2016. INNER JOIN AdventureWorks2016.
HumanResources.Employee e HumanResources.Employee e
ON p.BusinessEntityID = e.BusinessEntityID ON p.BusinessEntityID = e.BusinessEntityID
INNER JOIN INNER JOIN
(SELECT bea.BusinessEntityID, a.City (SELECT bea.BusinessEntityID, a.City
FROM AdventureWorks2016.Person.Address FROM AdventureWorks2016.Person.Address
AS a AS a
INNER JOIN AdventureWorks2016.Person. INNER JOIN AdventureWorks2016.Person.
BusinessEntityAddress AS bea BusinessEntityAddress AS bea
ON a.AddressID = bea.AddressID) AS d ON a.AddressID = bea.AddressID) AS d
ON p.BusinessEntityID = d.BusinessEntityID ON p.BusinessEntityID = d.BusinessEntityID
ORDER BY p.LastName, p.FirstName; ORDER BY p.LastName, p.FirstName;
WHITEPAPER 8
What about ACID transactions in NoSQL?
NoSQL databases also operate as operational systems with large numbers of transactions. When you flatten out a business
entity into multiple separate tables, you require a transaction for almost every update. With NoSQL databases, you don’t need
to flatten out the entity, but can usually contain it in a single document. Updates to a single document are atomic and don’t
require a transaction.
However, there may be updates that span multiple documents and require a check to ensure “all or nothing” of the transaction
occurs. For instance, a transfer of credits from one user’s account to another.
Java example:
.durabilityLevel(TransactionDurabilityLevel.PERSIST_TO_MAJORITY)
.logOnFailure(true, Event.Severity.WARN)
.build());
// Getting documents:
// Use ctx.getOptional if the document may or may not exist
Optional<TransactionGetResult> docOpt =
ctx.getOptional(collection, “doc-a”);
// Replacing a doc:
TransactionGetResult docB = ctx.get(collection, “doc-b”);
JsonObject content = docB.contentAs(JsonObject.class);
content.put(“transactions”, “are awesome”);
ctx.replace(docB, content);
// Removing a doc:
TransactionGetResult docC = ctx.get(collection, “doc-c”);
ctx.remove(docC);
ctx.commit();
});
WHITEPAPER 9
The combination of transactions and SQL greatly expand
the number of use cases where a NoSQL database can
be considered. In the past, the inability to join or handle
transactional operations meant that NoSQL databases
were only chosen for the highest volume and scale use
cases. But the option of using SQL and transactions means
that NoSQL databases can also be chosen for traditional
RDBMS cases that need more flexibility and power.
Because the data is stored and indexed all within the one
database product, it allows developers to connect to one
system and pass through the relevant requests.
WHITEPAPER 10
Operate at any scale
Databases that support web, mobile, and IoT applications must be able to operate at any scale. While it is possible to scale a
relational database like Oracle (using, for example, Oracle RAC), doing so is typically complex, expensive, and not fully reliable.
With Oracle, for example, scaling out using RAC technology requires numerous components and creates a single point of
failure that jeopardizes availability.
By comparison, a NoSQL distributed database – designed with a scale-out architecture and no single point of failure – provides
compelling operational advantages.
The database has to be able to scale reads, writes, and storage. This is a problem for relational databases that are limited
to scaling up – i.e., only being able to scale by adding more processors, memory, and storage to a single physical server
(sometimes known as “vertical scaling”). As a result, the ability to scale efficiently, and on demand, is a challenge. It becomes
increasingly expensive, because enterprises have to purchase bigger and bigger servers to accommodate more users and more
data. In addition, it can result in downtime if the database has to be taken offline to perform hardware upgrades.
A distributed NoSQL database runs on commodity hardware to scale out – i.e., add more resources simply by adding more
servers to a cluster (sometimes known as “horizontal scaling”). The ability to scale out enables enterprises to scale more
efficiently by (a) deploying no more hardware than is required to meet the current load; (b) applying less expensive hardware
and/or cloud infrastructure; and (c) scaling on demand and without downtime.
By distributing reads, writes, and storage across a cluster of nodes, NoSQL databases are able to operate at any scale.
Additionally, they are designed to be easy to configure, install, and manage both small and large clusters.
WHITEPAPER 11
Availability for always-on, global deployment
As more and more customer engagements take place
online via web and mobile apps, availability becomes a
major concern. These mission-critical applications have to
be available 24 hours a day, 7 days a week – no exceptions.
Delivering 24x7 availability is a challenge for relational
databases that are deployed to a single physical server or
that rely on clustering with shared storage. If the single
server or shared storage fails, the database becomes
unavailable, applications stop, and customers disengage.
In contrast to relational technology, a distributed, NoSQL database partitions and distributes data to multiple database
instances with no shared resources. Couchbase goes a step further and does this automatically.
In addition, the data can be replicated to one or more instances for high availability (intercluster replication) and in different
geographic locations. While relational databases like Oracle require separate software for replication, for example, Oracle
Active Data Guard, NoSQL databases do not – it’s built in and it’s automatic. Couchbase’s cross data center replication (XDCR)
feature also provides this automatically.
In addition, automatic failover ensures that if a node fails, the database can continue to perform reads and writes by sending
the requests to a different node. Again, Couchbase will perform this failover recovery and rebalancing automatically.
Customer behavior often requires organizations to support multiple physical, online, and mobile channels in multiple regions
and often multiple countries. While deploying a database to multiple data centers increases availability and helps with disaster
recovery, it also has the benefit of increasing performance too. All reads and writes can be executed on the nearest data
center, thereby reducing latency.
Ensuring global availability is difficult for relational databases where separate add-ons are required – which increase
complexity – or where replication between multiple data centers can only be used for failover, because only one data center is
active at a time. Oracle, for example, requires Oracle GoldenGate. When replicating between data centers, applications built on
relational databases can experience performance degradation or find that the data centers are severely out of sync.
WHITEPAPER 12
A distributed, NoSQL database includes built-in replication between data centers – no separate software is required.
In addition, some include bidirectional replication enabling full active-active deployments to multiple data centers. This
enables the database to be deployed in multiple countries or regions while providing local data access to local applications
and their users.
Deploying to multiple data centers not only improves performance, but enables immediate failover via hardware routers.
Applications don’t have to wait for the database to discover the failure and perform its own failover.
As enterprises shift to cloud, mobile, social media, and big data technologies, developers, architects, and operations
teams have to build and maintain web, mobile, and IoT applications faster, and at a greater scale. NoSQL is increasingly
the preferred database technology to power today’s web, mobile, and IoT applications.
Hundreds of Global 2000 enterprises, along with tens of thousands of smaller businesses and
startups, have adopted NoSQL. For many, the use of NoSQL started with caching, proof of concept,
or a small application, then expanded to targeted mission-critical applications, and can become
the foundation for all application development. Today, the Couchbase NoSQL database serves
thousands of these types of customers.
With NoSQL, enterprises are better able to both develop with agility and operate
at any scale – and to deliver the performance and availability required to meet
the demands of businesses.
WHITEPAPER 13
At Couchbase, we believe data is at the heart of the enterprise. We empower developers and
architects to build, deploy, and run their mission-critical applications. Couchbase delivers a high-
performance, flexible and scalable modern database that runs across the data center and any
cloud. Many of the world’s largest enterprises rely on Couchbase to power the core applications