19
NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014

NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

  • Upload
    others

  • View
    21

  • Download
    0

Embed Size (px)

Citation preview

Page 1: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

NoDBA Database For Ships At Lightspeed

Malcolm Matalka

Klarna AB

June 2014

Page 2: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

About

I Klarna is an ecommerce payments service from Sweden tryingto take over the world

I Heavy users of Erlang

I On second-generation purchase taking system

Page 3: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

NoDB

I Eventually consistent key-value database overlay

I Favors write-availability

I Synchronizes data between multiple systems

I Allows for large latencies

Page 4: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Eventual Consistency

I “guarantees that if no new updates are made to the object,eventually all accesses will return the last updated value” -Some ACM Article

I Popular EC DBs - Riak, Cassandra

I Generally quite different from what developers are used to

Page 5: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Why would anyone want EC???

I Scalability

I Availability

I Geolocality

I Great for caching!

Page 6: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Examples of EC Systems

I DNS

I Amazon

I Financial transactions

Page 7: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

InterPlaNet

Page 8: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Borg - That sounds Swedish

Page 9: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

First Contact

Page 10: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Write-availability

Page 11: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Really, what is NoDB?

I More of a model than an implementation

I Allows separate systems to share data

I Works across transactional stores and EC stores (read the fineprint)

I Not a database but a layer joining them

I Allows for out-of-order replication of data

I Inbetween step for going from monolith to SOA

Page 12: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Vector Clocks!!!!!!

Page 13: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

NoDB: The Implementation

I Implemented in Erlang

I Riak � Mnesia

I Mnesia is system of record

I Uses RabbitMQ as transport

I Realtime replication and manual exports

Page 14: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

NoDB: Mnesia Side

I Have a layer on top with a transaction log

I Listen in on transaction log

I Can iterate all keys in a table for export

I System of record

I Can replay history, great for catching up during downtime

I Vector clocks in shadow table

Page 15: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

NoDB: Riak Side

I PUT/GET/DEL through a NoDB API, writes to Riak &replicates

I Importer pulls off Rabbit and pushes directly to Riak

I Layer to locally queue exports when Rabbit is down

I Vector clock stored with data

Page 16: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

What’s an Update Look Like?

I Get your data

I Modify it and bump the vector clock

I Write to DB + replicate

I Mnesia wrapped up in an abstraction and we sneak the vectorclock into the transaction for the user (so kind!)

I On Mnesia, handle resolving possible siblings on write

I On Riak, handle resolving siblings on next update

Page 17: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Retrospective

I People hate using it. But they’re wrong

I Out of order events are hard to handle

I Being able to replay writes is really awesome (saved us fromlosing money multiple times)

Page 18: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Future Work

I Unify codebases, they were written in haste by different people

I Remove RabbitMQ, it’s not actually doing anything for ushere

I Make it easier for non-Erlang systems

I Postgres support??

Page 19: NoDB - A Database For Ships At Lightspeed · NoDB A Database For Ships At Lightspeed Malcolm Matalka Klarna AB June 2014. About IKlarna is an ecommerce payments service from Sweden

Questions?