SlideShare a Scribd company logo
FleetDB
A Schema-Free Database in Clojure

         Mark McGranaghan


          January 23, 2010
Motivation


Walkthrough


Implementation
Motivation
Motivation



       optimize for agile development
Walkthrough



     Client Quickstart
     Basic Queries
     Concurrency Tools
Client Quickstart



  (use ’fleetdb.client)
  (def client (connect))

  (client ["ping"])
  => "pong"
Insert



  (client
    ["insert" "accounts"
      {"id" 1 "owner" "Eve" "credits" 100}])
Insert



  (client
    ["insert" "accounts"
      {"id" 1 "owner" "Eve" "credits" 100}])

  => 1
Select



  (client
    ["select" "accounts" {"where" ["=" "id" 1]}])
Select



  (client
    ["select" "accounts" {"where" ["=" "id" 1]}])

  => [{"id" 1 "owner" "Eve" "credits" 100}]
Select with Conditions



  (client
    ["select" "accounts"
      {"where" [">=" "credits" 150]}])
Select with Order and Limit



  (client
    ["select" "accounts"
      {"order" ["credits" "asc"] "limit" 2}])
Update



  (client
    ["update" "accounts" {"credits" 105}
      {"where" ["=" "owner" "Eve"]}])
Explain (I)


  (client
    ["explain" ["select" "accounts"
                 {"where" ["=" "owner" "Eve"]}]])
Explain (I)


  (client
    ["explain" ["select" "accounts"
                 {"where" ["=" "owner" "Eve"]}]])

  => ["filter" ["=" "owner" "Eve"]
       ["collection-scan" "accounts"]]
Create Index



  (client
    ["create-index" "accounts" "owner"])
Explain (II)



  (client
    ["explain" ["select" "accounts"
                 {"where" ["=" "owner" "Eve"]}]])

  => ["index-lookup" ["accounts" "owner" "Eve"]]]
Multi-Write
Multi-Write



  (client
    ["multi-write"
     [write-query-1 write-query-2 ...]])
Multi-Write



  (client
    ["multi-write"
     [write-query-1 write-query-2 ...]])

  => [result-1 result-2 ...]
Checked-Write
Checked-Write


  (client
    ["checked-write"
     read-query
     expected-read-result
     write-query])
Checked-Write


  (client
    ["checked-write"
     read-query
     expected-read-result
     write-query])

  => [true write-result]
Checked-Write


  (client
    ["checked-write"
     read-query
     expected-read-result
     write-query])

  => [true write-result]

  => [false actual-read-result]
Implementation



     Background
     Organization
     Key ideas
Background



    http://clojure.org/data_structures
    http://clojure.org/sequences
    http://clojure.org/state
Organization
Organization



     fleetdb.core: pure functions
Organization



     fleetdb.core: pure functions
     fleetdb.embedded: identity and durability
Organization



     fleetdb.core: pure functions
     fleetdb.embedded: identity and durability
     fleetdb.server: network interface
fleetdb.core



    Pure functions
fleetdb.core



    Pure functions
    Databases as Clojure data structures
fleetdb.core



    Pure functions
    Databases as Clojure data structures
    Read: db + query → result
fleetdb.core



    Pure functions
    Databases as Clojure data structures
    Read: db + query → result
    ‘Write’: db + query → result + new db
fleetdb.core Query Planner
fleetdb.core Query Planner

    Implements declarative queries
fleetdb.core Query Planner

    Implements declarative queries
    Database + query → plan
fleetdb.core Query Planner

      Implements declarative queries
      Database + query → plan

  ["select" "accounts"
    {"where" ["=" "owner" "Eve"]}]
fleetdb.core Query Planner

      Implements declarative queries
      Database + query → plan

  ["select" "accounts"
    {"where" ["=" "owner" "Eve"]}]

  ["filter" ["=" "owner" "Eve"]
    ["record-scan" "accounts"]]
fleetdb.core Query Planner

      Implements declarative queries
      Database + query → plan

  ["select" "accounts"
    {"where" ["=" "owner" "Eve"]}]

  ["filter" ["=" "owner" "Eve"]
    ["record-scan" "accounts"]]

  ["index-lookup" ["accounts" "owner" "Eve"]]
fleetdb.core Query Executor
fleetdb.core Query Executor


    Database + plan → result
fleetdb.core Query Executor


      Database + plan → result

  ["filter" ["=" "owner" "Eve"]
    ["record-scan" "accounts"]]
fleetdb.core Query Executor


      Database + plan → result

  ["filter" ["=" "owner" "Eve"]
    ["record-scan" "accounts"]]

  (filter (fn [r] (= (r "owner") "Eve"))
    (vals (:rmap (db "accounts"))))
fleetdb.embedded



    Wraps fleetdb.core
fleetdb.embedded



    Wraps fleetdb.core
    Adds identity and durability
fleetdb.embedded



    Wraps fleetdb.core
    Adds identity and durability
    Databases in atoms
fleetdb.embedded



    Wraps fleetdb.core
    Adds identity and durability
    Databases in atoms
    Append-only log
fleetdb.embedded Read Path
fleetdb.embedded Read Path



    Dereference database atom
fleetdb.embedded Read Path



    Dereference database atom
    Pass to fleetdb.core
fleetdb.embedded Read Path



    Dereference database atom
    Pass to fleetdb.core
    Return result
fleetdb.embedded Write Path
fleetdb.embedded Write Path


    Enter fair lock
fleetdb.embedded Write Path


    Enter fair lock
    Dereference database atom
fleetdb.embedded Write Path


    Enter fair lock
    Dereference database atom
    Pass to fleetdb.core
fleetdb.embedded Write Path


    Enter fair lock
    Dereference database atom
    Pass to fleetdb.core
    Append query to log
fleetdb.embedded Write Path


    Enter fair lock
    Dereference database atom
    Pass to fleetdb.core
    Append query to log
    Swap in new database value
fleetdb.embedded Write Path


    Enter fair lock
    Dereference database atom
    Pass to fleetdb.core
    Append query to log
    Swap in new database value
    Return result
fleetdb.server



    Wraps fleetdb.embedded
fleetdb.server



    Wraps fleetdb.embedded
    Adds JSON client API
Aside: Source Size
Aside: Source Size


                Lines of Code
              core         630
              embedded 130
              server       120
              lint         280
              utilities    140
              total       1300
Takeaways
Takeaways



     Clojure’s data structures are awesome
Takeaways



     Clojure’s data structures are awesome
     Clojure is viable for infrastructure software
Takeaways



     Clojure’s data structures are awesome
     Clojure is viable for infrastructure software
     Try FleetDB!
Learn More



     http://FleetDB.org
     http://github.com/mmcgrana

More Related Content

What's hot (20)

PDF
The Ring programming language version 1.5.3 book - Part 40 of 184
Mahmoud Samir Fayed
 
PDF
Google App Engine Developer - Day4
Simon Su
 
PDF
Cache metadata
Joris Vercammen
 
ODP
Aggregation Framework in MongoDB Overview Part-1
Anuj Jain
 
PPT
Spring data iii
명철 강
 
PDF
Aggregation Framework MongoDB Days Munich
Norberto Leite
 
PDF
Presto in Treasure Data
Mitsunori Komatsu
 
PDF
Android HttpClient - new slide!
Chalermchon Samana
 
PDF
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Altinity Ltd
 
PDF
MariaDB and Clickhouse Percona Live 2019 talk
Alexander Rubin
 
PDF
The Ring programming language version 1.9 book - Part 49 of 210
Mahmoud Samir Fayed
 
PPTX
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays
 
PPTX
Slick: Bringing Scala’s Powerful Features to Your Database Access
Rebecca Grenier
 
PDF
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
MongoDB
 
PDF
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Cliff Seal
 
PPTX
Apache spark
Arnon Rotem-Gal-Oz
 
PDF
Utilizing Powerful Extensions for Analytics and Operations
Neo4j
 
PDF
Green dao
彥彬 洪
 
PDF
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
Altinity Ltd
 
PPTX
MongoDB World 2016 : Advanced Aggregation
Joe Drumgoole
 
The Ring programming language version 1.5.3 book - Part 40 of 184
Mahmoud Samir Fayed
 
Google App Engine Developer - Day4
Simon Su
 
Cache metadata
Joris Vercammen
 
Aggregation Framework in MongoDB Overview Part-1
Anuj Jain
 
Spring data iii
명철 강
 
Aggregation Framework MongoDB Days Munich
Norberto Leite
 
Presto in Treasure Data
Mitsunori Komatsu
 
Android HttpClient - new slide!
Chalermchon Samana
 
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
Altinity Ltd
 
MariaDB and Clickhouse Percona Live 2019 talk
Alexander Rubin
 
The Ring programming language version 1.9 book - Part 49 of 210
Mahmoud Samir Fayed
 
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
apidays
 
Slick: Bringing Scala’s Powerful Features to Your Database Access
Rebecca Grenier
 
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
MongoDB
 
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Cliff Seal
 
Apache spark
Arnon Rotem-Gal-Oz
 
Utilizing Powerful Extensions for Analytics and Operations
Neo4j
 
Green dao
彥彬 洪
 
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
Altinity Ltd
 
MongoDB World 2016 : Advanced Aggregation
Joe Drumgoole
 

Viewers also liked (20)

PDF
Database Schema
Jimmy Chu
 
KEY
Schema Design with MongoDB
rogerbodamer
 
PDF
Clojure presentation
Jéferson Machado
 
PDF
Database schema handbook for cisco unified icm contact center enterprise & ho...
Bashar Hasan
 
PDF
FleetDB
Diego Pacheco
 
PPT
A House Is Not A Home Version 1 3 Minus
Brower Entertainment
 
PPT
House and home
Olga Sokolik
 
PPT
Database 2 External Schema
Ashwani Kumar Ramani
 
PPTX
House
Snehal Bhargava
 
PPTX
a house a home
Apm Ibn Ahmad
 
PPT
Best Practices for Database Schema Design
Iron Speed
 
PPTX
C1 Topic 6 House & Home
Nina's Cabbages
 
KEY
Home and House idioms
Vera Surkova
 
PPTX
مقدمة في قواعد البيانات
Mahmoud Almadhoun
 
PPSX
Databases قواعد البيانات
Mohamed Reda
 
DOCX
Báo cáo bài tập lớn môn Cơ sở dữ liệu - Học viện công nghệ bưu chính viễn thông
Huyen Pham
 
PPT
أساسيات قواعد البيانات
Bandar Alhazmi
 
PPTX
Database schema
Mahmoud Almadhoun
 
DOCX
تخطيط قاعده بيانات مدرسه
Omar Computer Teacher
 
DOCX
اسئلة قواعد البيانات
Mohamed Sayed
 
Database Schema
Jimmy Chu
 
Schema Design with MongoDB
rogerbodamer
 
Clojure presentation
Jéferson Machado
 
Database schema handbook for cisco unified icm contact center enterprise & ho...
Bashar Hasan
 
FleetDB
Diego Pacheco
 
A House Is Not A Home Version 1 3 Minus
Brower Entertainment
 
House and home
Olga Sokolik
 
Database 2 External Schema
Ashwani Kumar Ramani
 
a house a home
Apm Ibn Ahmad
 
Best Practices for Database Schema Design
Iron Speed
 
C1 Topic 6 House & Home
Nina's Cabbages
 
Home and House idioms
Vera Surkova
 
مقدمة في قواعد البيانات
Mahmoud Almadhoun
 
Databases قواعد البيانات
Mohamed Reda
 
Báo cáo bài tập lớn môn Cơ sở dữ liệu - Học viện công nghệ bưu chính viễn thông
Huyen Pham
 
أساسيات قواعد البيانات
Bandar Alhazmi
 
Database schema
Mahmoud Almadhoun
 
تخطيط قاعده بيانات مدرسه
Omar Computer Teacher
 
اسئلة قواعد البيانات
Mohamed Sayed
 
Ad

Similar to FleetDB: A Schema-Free Database in Clojure (20)

PDF
Microservices in Clojure
Lucas Cavalcanti dos Santos
 
PPTX
Python Ireland Conference 2016 - Python and MongoDB Workshop
Joe Drumgoole
 
PDF
Big Data for Mobile
BugSense
 
PDF
Extend db
Sridhar Valaguru
 
PDF
NoSQL and CouchDB
João Cerdeira
 
PPTX
I say NoSQL you say what
Pratik Khasnabis
 
KEY
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
jorgeortiz85
 
PDF
The productivity brought by Clojure
Laurence Chen
 
PPT
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
JAX London
 
PDF
learn you some erlang - chap 9 to chap10
경미 김
 
PPTX
Webinar: MongoDB and Polyglot Persistence Architecture
MongoDB
 
PDF
Testing stateful, concurrent, and async systems using test.check
Eric Normand
 
PPTX
NOSQL and MongoDB Database
Tariqul islam
 
PDF
MongoDB @ SourceForge
iammutex
 
PPTX
No sql solutions - 공개용
Byeongweon Moon
 
PDF
mongodb-introduction
Tse-Ching Ho
 
PPT
OmniBase Object Database
ESUG
 
PPTX
Introducing N1QL: New SQL Based Query Language for JSON
Keshav Murthy
 
ODP
Intravert Server side processing for Cassandra
Edward Capriolo
 
ODP
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
DataStax Academy
 
Microservices in Clojure
Lucas Cavalcanti dos Santos
 
Python Ireland Conference 2016 - Python and MongoDB Workshop
Joe Drumgoole
 
Big Data for Mobile
BugSense
 
Extend db
Sridhar Valaguru
 
NoSQL and CouchDB
João Cerdeira
 
I say NoSQL you say what
Pratik Khasnabis
 
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
jorgeortiz85
 
The productivity brought by Clojure
Laurence Chen
 
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
JAX London
 
learn you some erlang - chap 9 to chap10
경미 김
 
Webinar: MongoDB and Polyglot Persistence Architecture
MongoDB
 
Testing stateful, concurrent, and async systems using test.check
Eric Normand
 
NOSQL and MongoDB Database
Tariqul islam
 
MongoDB @ SourceForge
iammutex
 
No sql solutions - 공개용
Byeongweon Moon
 
mongodb-introduction
Tse-Ching Ho
 
OmniBase Object Database
ESUG
 
Introducing N1QL: New SQL Based Query Language for JSON
Keshav Murthy
 
Intravert Server side processing for Cassandra
Edward Capriolo
 
NYC* 2013 - "Advanced Data Processing: Beyond Queries and Slices"
DataStax Academy
 
Ad

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Digital Circuits, important subject in CS
contactparinay1
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 

FleetDB: A Schema-Free Database in Clojure