Is there a trendy new database that everyone’s talking about on Hacker News? Use the trendy new database! Yes Use whatever I used last time, I guess. No
What are different ways to organize data? SQL Relational Database Management System (RDBMS) PostgreSQL MySQL Oracle SQL Server DB2 NoSQL Document Store MongoDB CouchDB Key-Value Store Redis Cassandra Graph Database Distributed Analytics Etc.
Fundamental Concepts of Databases Transaction a unit of work performed within a database management system Table / Collection a grouping of records Tuple / Row / Document a single record of related data Schema a definition of attributes and relations, imposed on records ACID a set of properties that guarantee that transactions are processed reliably
Atomicity (ACID) Every transaction is all or nothing If one part of the transaction fails, the entire transaction fails account_1 $10 account_2 $0 Transaction to transfer $10 between two accounts
Atomicity (ACID) Every transaction is all or nothing If one part of the transaction fails, the entire transaction fails account_1 $0 account_2 $0 Transaction to transfer $10 between two accounts
Consistency (ACID) Every transaction brings the database from one valid state to another phone_numbers 0123456789 9876543210 01234567890 Inconsistent insertion in column with custom data type checking
Isolation (ACID) No transaction can interfere with another In other words, the effects of concurrent transactions should be the same as if the transactions were run serially in arbitrary order account_1 $10 Process 1 val = account_1 val += $10 account_1 = val Process 2 val = account_1 val += $10 account_1 = val
NoSQL: Schema Flexibility Pros Plan for uncertain requirements and change schemas on the fly Store data records with different attributes Avoid slow JOINs Cons Schema enforces data validity, type checking Many complex data structures can be nicely modeled using a schema
Customers should be able to view and add items to their shopping cart even if… data centers are being destroyed by tornadoes. Source: “Dynamo: Amazon’s Highly Available Key-value “
DynamoDB: Consistency Amazon avoids downtime at ALL costs. Consistency problems are rare and can be dealt with by customer service. Plus, good to keep items in shopping carts :)
Things to think about What components of ACID do you need? Does schema flexibility make sense for your application? Do you need massive scale? (Probably not) Codebase maturity: old isn’t bad!