POLYGLOT

PERSISTENCE IN
TODAY'S WORLD

Armagan Amcalar

Sabanci University, Istanbul
May 15th, 2014

who am i?

Armagan Amcalar
Co-founder, Chief Software Architect
Startup Kitchen

        dashersw             aamcalar

hobby projects

pedals.io
trax.io

BACKGROUND

2007 - BSc. in Microelectronics,
Sabanci University

2010 - MSc in Electronics Engineering,
Sabanci University

Startup Kitchen

line.do
isteoyun.com
dinlet.io
fub.io
typ.mx
kixel.co
driwe.co
mettoapp.com

Summary

  1. Persistence yesterday
  2. The needs today
  3. Polyglot persistence
  4. NoSQL movement
  5. Document databases — MongoDB
  6. Key-value pair stores — Redis
  7. Graph databases — Neo4J

Keywords

Polyglot

NoSQL, MongoDB

ACID

Scalability (horizontal vs vertical)

Replication (as in master-slave)

JSON

Data normalisation

Map-reduce

REST

Persistence Yesterday

  • Databases with a few million records on huge, single mainframe computers
  • Shared database integration
  • No real-time querying necessary, overnight analysis
  • Develop once, use for years
  • ACID
  • Data-first
  • Impedance mismatch

The Needs Today

  • Billions of records for millions of users - mass data storage
  • Impedance match
  • Cheaper hardware; scale horizontally vs vertically
  • Distributed across geographical regions
  • Fail-over systems, clusters; sharding, master-slave replication
  • Evolving architecture, software; faster development times, developer productivity, schemaless design

the Needs Today

  • More specific use-cases
  • Real-time queries in thousands of requests each second
  • Highly connected data
  • More data-models, aggregates
  • ACID, CAP, Eventual Consistency
  • Detail analytics, map-reduce
  • Data access-firs, aggregates

law of the instrument

...it is tempting, if the only tool you have is a hammer,
to treat everything as if it were a nail.

EXAMPLE: E-COMMERCE PLATFORM

  • Inventory
  • Orders
  • Shopping cart
  • Session data
  • Search and recommendations
  • Social add-ons
  • Analytics

all relational

Polyglot

NoSQL Databases

  • Object oriented
  • Key-value pair stores
  • Document databases
  • Graph databases
  • Column stores

Relational Data Model

Document DB Data Model

Document DB Data Model Alternative

            
{
    "customer": {
        "id": 1,
        "name": "Martin",
        "billingAddress": [{ "city": "Chicago" }],
        "orders": [{
            "id": 99,
            "customerId": 1,
            "orderItems": [{
                "productId": 27,
                "price": 32.45,
                "productName": "NoSQL Distilled"
            }],
            "shippingAddress": [{ "city": "Chicago" }],
            "orderPayment": [{
                "ccinfo": "1000-1000-1000-1000",
                "txnId": "abelif879rft",
                "billingAddress": { "city": "Chicago" }
            }]
        }]
    }
}
        

 

graph db model

MongoDB

  • Productivity boost, JSON based
  • Scalable on cheap hardware
  • SQL-like querying capabilities
  • Document-based data storage
  • Schemaless design
  • Aggregates and low-connected data

MongoDB Queries

SQL

MongoDB

Redis

  • Fast. Very fast.
  • Small and powerful data structures,
    lists, sets, hashes
  • Assembly like instructions
  • REST API
  • In-memory
  • Pub/sub
  • Item expiration

Redis Instructions

  • SET key value
  • GET key
  • DEL key
  • INCR key
  • EXPIRE key
  • RPUSH (right push) key value
  • LPUSH (left push) key value
  • LRANGE key start end
  • SADD (set add) key value
  • SREM key
  • SMEMBERS key
  • ZADD (sorted sets) key score value
  • HSET (hash set) key value
  • HMSET (multi set) key field value …
  • HINCRBY key field

Neo4J

  • Data is mostly a set of connections, and it's those connections what matter most
  • Properties on connections
  • Very fast on graph modelling and search
  • REST API

Example Graph

Neo4J queries

References

  • Martin Fowler. “NoSQL Distilled: A Brief Guide to the Emerging World of Polyglot Persistence.”
  • Martin Fowler. Patterns of Enterprise Application Architecture. Addison-Wesley. 2003. ISBN 0321127420.
  • http://www.mongodb.org
  • http://try.redis.io
  • http://redis.io/topics/twitter-clone
  • http://www.neo4j.org

thank you!

Let's keep in touch!

Armagan Amcalar

armagan@amcalar.com
twitter: @aamcalar
github: dashersw
blog: arm.ag

Polyglot Persistence in Today's World

By Armağan Amcalar

Polyglot Persistence in Today's World

The demanding need to serve millions of users in today’s web applications require drastic measures. To keep up with the pace of users and customers, developers have to act fast, efficient and operate in multiple geographical regions. This motive demands specialised database systems for specific use cases in order to maximize efficiency. In this talk, we’ll explore three different NoSQL database types, key-value pair stores, document databases and graph databases, and their use in a real world scenario.

  • 4,716