18. BASE in Action
1st Bank
checking savings
customers
Transfer $1000 from
1st Bank checking to
Bank of Foo savings
Bank of Foo
account account_type
customer
21. "When designing distributed web services, there
are three properties that are commonly desired:
consistency, availability, and partition tolerance.
It is impossible to achieve all three."
- "Brewer's Conjecture and the Feasibility of Consistent,
Available, Partition-Tolerant Web Services"
Seth Gilbert and Nancy Lynch (MIT)
27. Relations
(tables, joins, integrity)
ACID guarantees
Query using SQL Strict schema
Difficult to scale,
partition
(e.g. 2-phase commit)
By far most popular persistence choice today
Mismatch with
OO languages
28. select *
from fakenames f
where f.surname like 'Smi%'
and f.city = 'Richmond'
and f.state = 'VA'
order by f.surname, f.given_name;
28
33. "As opposed to Relational Databases, document-based
databases do not store data in tables with uniform sized
fields for each record. Instead, each record is stored as a
document that has certain characteristics. Any number of
fields of any length can be added to a document. Fields can
also contain multiple pieces of data."
- Wikipedia
(http://en.wikipedia.org/wiki/Document-oriented_database)
41. Views
JavaScript as description language
Map/Reduce functions
Add structure to semi-structured data
Independent of actual documents
(created in special Design Documents)
43. // Map function to find Seattlites
function(doc) {
if (doc.State == "WA" && doc.City == "Seattle") {
emit(doc.Number,
{ "GivenName":doc.GivenName, "Surname":doc.Surname });
}
}
43
44. // Map function
function(doc) {
emit(doc.State, 1);
}
// Reduce function; aggregates counts
function (key, values) {
return sum(values);
}
44
Counting people by state...
45. Views are not meant to be created
dynamically like SQL queries!
Caution:
To keep view querying fast, the view engine maintains
indexes of its views, and incrementally updates them to
reflect changes in the database. CouchDB’s core
design is largely optimized around the need for
efficient, incremental creation of views and
their indexes.
- http://couchdb.apache.org/docs/overview.html
47. "Amazon SimpleDB is a web service for running queries on
structured data in real time. This service works in close
conjunction with Amazon Simple Storage Service (Amazon S3)
and Amazon Elastic Compute Cloud (Amazon EC2), collectively
providing the ability to store, process and query data sets in
the cloud. These services are designed to make web-scale
computing easier and more cost-effective for developers."
- SimpleDB Developer Guide
(Version 2007-11-07)
48. "A traditional, clustered relational database requires a sizable
upfront capital outlay, is complex to design, and often requires a
DBA to maintain and administer.Amazon SimpleDB is
dramatically simpler, requiring no schema, automatically
indexing your data and providing a simple API for storage
and access.This approach eliminates the administrative
burden of data modeling, index maintenance, and performance
tuning. Developers gain access to this functionality within
Amazon’s proven computing environment, are able to scale
instantly, and pay only for what they use."
- SimpleDB Developer Guide
(Version 2007-11-07)
49. Organize data into domains
Domains have items
Items have attributes
Attributes have value(s)
54. AmazonSimpleDB service =
new AmazonSimpleDBClient(accessKeyId, secretAccessKey);
// Create a new domain
CreateDomainRequest cdReq =
new CreateDomainRequest().withDomainName("Fakenames");
CreateDomainResponse cdResp = service.createDomain(cdReq);
// List all our domains
ListDomainsRequest ldReq = new ListDomainsRequest();
ListDomainsResponse ldResp = service.listDomains(ldReq);
54
61. // Get a count
String query = "select count(*) from Fakenames";
SelectRequest request =
new SelectRequest().withSelectExpression(query);
SelectResponse response = service.select(request);
61
62. // Select Richmonders
String query = "select * from Fakenames"
+ " where city = 'Richmond' intersection state = 'VA'"
+ " intersection surname like 'Smi%'";
SelectRequest request =
new SelectRequest().withSelectExpression(query);
SelectResponse response = service.select(request);
62
63. There are Limits!
Query execution time <= 5 sec
Max items in query response = 250
See SimpleDB Developer Guide for more...
Size limits <= 1024 bytes
Attribute limit per item <= 256
65. Eventually consistent(*)
"Amazon SimpleDB keeps multiple copies of each
domain.When data is written or updated...all copies of
the data are updated. However, it takes time for the
data to propagate to all storage locations.The data will
eventually be consistent, but an immediate read
might not show the change. Consistency is usually
reached within seconds, but a high system load or
network partition might increase this time. Performing
a read after a short period of time should return the
updated data."
(Version 2007-11-07)
- SimpleDB Developer Guide
66. (*) ConsistentRead
Version 2009-04-15 added consistent read option
"If eventually consistent reads are not
acceptable for your application, use
ConsistentRead.Although this operation
might take longer than a standard read, it
always returns the last updated value."
(Version 2009-04-15)
- SimpleDB Developer Guide
71. Distributed key-value
storage system
Used by Amazon core and web services
(e.g. your Amazon shopping cart...)
Massively
scaleable
Fault tolerant
Eventually
consistent
73. What is it?
"a distributed key-value storage system"
automatic replication across multiple servers
transparent server failure handling
automatic data item versioning
74. "Voldemort is not a relational database, it does not
attempt to satisfy arbitrary relations while satisfying ACID
properties. Nor is it an object database that attempts to
transparently map object reference graphs. Nor does it
introduce a new abstraction such as document-
orientation. It is basically just a big, distributed,
persistent, fault-tolerant hash table."
http://project-voldemort.com/
75. designed for horizontal scaling
used at LinkedIn "for certain high-scalability
storage problems where simple functional
partitioning is not sufficient"
76. "Consistent hashing"
No single server holds all data
Data partitioned across multiple servers
Versioning using "vector clocks"
77. Configuration:
cluster.xml describes cluster
(servers, data partitions)
stores.xml describes data stores
(persistence, routing, key/value data format, replication factor,
preferred reads/writes, required reads/writes)
80. > locate "1"
Node 0
host: localhost
port: 6666
available: yes
last checked: 96171 ms ago
Node 1
host: localhost
port: 6667
available: yes
last checked: 96171 ms ago
Node 2
host: localhost
port: 6668
available: yes
last checked: 96172 ms ago
80
replication
81. $ ./voldemort-shell.sh people tcp://localhost:6666
Established connection to people via tcp://localhost:6666
> put "1" { "GivenName":"Bob", "Surname":"Smith" }
> get "1"
version(0:1): {"GivenName":"Bob", "Surname":"Smith", }
> put "1" { "GivenName":"Robert", "Surname":"Smith", }
> get "1"
version(0:2): {"GivenName":"Robert", "Surname":"Smith", }
81
vector clock
(master node: version)
82. StoreClientFactory factory =
new SocketStoreClientFactory(numThreads,
numThreads, maxQueuedRequests, maxConnectionsPerNode,
maxTotalConnections, bootstrapUrl);
StoreClient<Integer, Map<String, Object>> client =
factory.getStoreClient("fakenames");
// Update a value
Versioned versioned = client.get(1);
Map<String, Object> person = versioned.getValue();
person.put("EmailAddress", newEmailAddr);
versioned.setObject(person);
client.put(1, versioned);
82
Java API example
84. - Bigtable:A Distributed Storage System
for Structured Data
http://labs.google.com/papers/bigtable.html
"Bigtable is a distributed storage
system for managing structured data
that is designed to scale to a very
large size: petabytes of data across
thousands of commodity
servers. Many projects at Google
store data in Bigtable including web
indexing, Google Earth, and Google
Finance."
85. "A Bigtable is a sparse, distributed, persistent
multidimensional sorted map"
- Bigtable:A Distributed Storage System
for Structured Data
http://labs.google.com/papers/bigtable.html
88. (row key, column key, timestamp) => value
The map is indexed by a row key,
column key, and a timestamp; each
value in the map is an uninterpreted array
of bytes.
- Bigtable:A Distributed Storage System
for Structured Data
http://labs.google.com/papers/bigtable.html
93. HBase uses a data model very similar to that of Bigtable.
Applications store data rows in labeled tables.A data row
has a sortable row key and an arbitrary number of
columns.The table is stored sparsely, so that rows in
the same table can have widely varying numbers of
columns.
- http://wiki.apache.org/hadoop/Hbase/HbaseArchitecture
94. hbase(main):001:0> create 'blog', 'info', 'content'
0 row(s) in 4.3640 seconds
hbase(main):002:0> put 'blog', '20090320162535', 'info:title', 'Document-oriented
storage using CouchDB'
0 row(s) in 0.0330 seconds
hbase(main):003:0> put 'blog', '20090320162535', 'info:author', 'Bob Smith'
0 row(s) in 0.0030 seconds
hbase(main):004:0> put 'blog', '20090320162535', 'content:', 'CouchDB is a
document-oriented...'
0 row(s) in 0.0030 seconds
hbase(main):005:0> put 'blog', '20090320162535', 'info:category', 'Persistence'
0 row(s) in 0.0030 seconds
hbase(main):006:0> get 'blog', '20090320162535'
COLUMN CELL
content: timestamp=1239135042862, value=CouchDB is a doc...
info:author timestamp=1239135042755, value=Bob Smith
info:category timestamp=1239135042982, value=Persistence
info:title timestamp=1239135042623, value=Document-oriented...
4 row(s) in 0.0140 seconds
94
HBase Shell
97. // Create a new table
HBaseAdmin admin = new HBaseAdmin(new HBaseConfiguration());
HTableDescriptor descriptor = new HTableDescriptor("mytable");
descriptor.addFamily(new HColumnDescriptor("family1:"));
descriptor.addFamily(new HColumnDescriptor("family2:"));
descriptor.addFamily(new HColumnDescriptor("family3:"));
admin.createTable(descriptor);
97
98. // Add some data into 'mytable'
HTable table = new HTable("mytable");
BatchUpdate update = new BatchUpdate("row1");
update.put("family1:aaa", Bytes.toBytes("some value"));
table.commit(update);
// Get data back
RowResult result = table.getRow("row1");
Cell cell = result.get("family1:aaa");
// Overwrite earlier value and add more data
BatchUpdate update2 = new BatchUpdate("row1");
update2.put("family1:aaa", Bytes.toBytes("some value"));
update2.put("family2:bbb", Bytes.toBytes("another value"));
table.commit(update2);
98
99. Finding data:
get (by row key)
scan (by row key ranges, filtering)
Secondary indexes allow scanning
by different keys
(a bit more flexibility, requires more storage)
100. // Scan for people born during January 1960
HTable table = new HTable("fakenames");
byte[][] columns =
Bytes.toByteArrays(new String[]{ "name:", "gender:" });
byte[] startRow = Bytes.toBytes("19600101");
byte[] endRow = Bytes.toBytes("19600201");
Scanner scanner = table.getScanner(columns, startRow, endRow);
for (RowResult result: scanner) {
...
}
scanner.close();
100
102. one size does
not fit all
lots of alternatives
think about what you
really need...
(not what's currently "hot")
103. What do you really need?
distributed
deployment?
fault
tolerance?
query
richness?
schema
evolution?
extreme
scalability?
ability to enforce
relationships?
ACID or BASE?
key/value
storage?
106. General
Polyglot Persistence
http://www.sleberknight.com/blog/sleberkn/entry/polyglot_persistence
Database Thaw
http://martinfowler.com/bliki/DatabaseThaw.html
Application Design in the context of the shifting storage spectrum
http://qconsf.com/sf2008/presentation/Application+Design+in+the+context+of+the+shifting+storage+spectrum
BASE:An Acid Alternative
http://queue.acm.org/detail.cfm?id=1394128
The Challenges of Latency
http://www.infoq.com/articles/pritchett-latency
One size fits all:A concept whose time has come and gone
http://www.databasecolumn.com/2007/09/one-size-fits-all.html
http://www.cs.brown.edu/~ugur/fits_all.pdf
The End of an Architectural Era (It's Time for a Complete Rewrite)
http://db.cs.yale.edu/vldb07hstore.pdf
Brewer’s Conjecture and the Feasibility of Consistent,Available, Partition-Tolerant Web Services
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.20.1495
107. General
Semi-Structured Data
http://www.dcs.bbk.ac.uk/~ptw/teaching/ssd/toc.html
Latency is Everywhere and it CostsYou Sales - How to Crush it
http://highscalability.com/latency-everywhere-and-it-costs-you-sales-how-crush-it
QCon London 2009: Database projects to watch closely
http://gojko.net/2009/03/11/qcon-london-2009-database-projects-to-watch-closely
Memories, Guesses, and Apologie
http://blogs.msdn.com/pathelland/archive/2007/05/15/memories-guesses-and-apologies.aspx
Column-oriented databases
http://en.wikipedia.org/wiki/Column-oriented_DBMS
Entity-Attribute-Value model
http://en.wikipedia.org/wiki/Entity-Attribute-Value_model
Read Consistency: Dumb Databases, Smart Services
http://blog.labnotes.org/2007/09/20/read-consistency-dumb-databases-smart-services/
Neo4j graph database
http://neo4j.org/
NoSql web site - "Your Ultimate Guide to the Non-Relational Universe"
http://nosql-database.org/
109. Document-Oriented Databases
CouchDB - A Use Case
http://kore-nordmann.de/blog/couchdb_a_use_case.html
Amazon SimpleDB
http://aws.amazon.com/simpledb/
http://en.wikipedia.org/wiki/SimpleDB
thrudb - Document Oriented Database Services
http://code.google.com/p/thrudb/
thrudb - faster, cheaper than SimpleDB
http://www.igvita.com/2007/12/28/thrudb-faster-and-cheaper-than-simpledb/
QCon 2008 track on Document-Oriented Distributed Databases
http://qconsf.com/sf2008/tracks/show_track.jsp?trackOID=170
110. Distributed K-V Stores
Amazon's Dynamo
http://www.allthingsdistributed.com/2007/10/amazons_dynamo.html
http://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf
Anti-RDBMS:A list of distributed key-value stores
http://www.metabrew.com/article/anti-rdbms-a-list-of-distributed-key-value-stores/
http://www.reddit.com/r/programming/comments/7qv19/antirdbms_a_list_of_distributed_keyvalue_stores/
Is the Relational Database Doomed?
http://developers.slashdot.org/comments.pl?sid=1127539&cid=26849641
ProjectVoldemort
http://project-voldemort.com/
ProjectVoldemort design (also see excellent list of references from this page)
http://project-voldemort.com/design.php
Consistent Hashing
http://en.wikipedia.org/wiki/Consistent_hashing
111. Bigtable / HBase
Google Architecture
http://highscalability.com/google-architecturehttp://highscalability.com/google-architecture
Bigtable:A Distributed Storage System for Structured Data
http://en.wikipedia.org/wiki/BigTable
http://labs.google.com/papers/bigtable.html
http://labs.google.com/papers/bigtable-osdi06.pdf
Apache HBase
http://hadoop.apache.org/hbase/
http://en.wikipedia.org/wiki/HBase
Apache Hadoop
http://hadoop.apache.org/
Understanding HBase and BigTable
http://jimbojw.com/wiki/index.php?title=Understanding_Hbase_and_BigTable
Matching Impedance:When to use HBase
http://blog.rapleaf.com/dev/?p=26
HBase Leads Discuss Hadoop, BigTable and Distributed Databases
http://www.infoq.com/news/2008/04/hbase-interview
Hadoop/HBase vs RDBMS
http://www.docstoc.com/docs/2996433/Hadoop-and-HBase-vs-RDBMS