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

PDF
FleetDB A Schema-Free Database in Clojure
PPTX
MongoDB - Aggregation Pipeline
PPTX
MongoDB Aggregation
PDF
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
PPT
SharePoint Administration with PowerShell
PPTX
Getting Started with MongoDB and NodeJS
PDF
The Ring programming language version 1.10 book - Part 50 of 212
PDF
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
FleetDB A Schema-Free Database in Clojure
MongoDB - Aggregation Pipeline
MongoDB Aggregation
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
SharePoint Administration with PowerShell
Getting Started with MongoDB and NodeJS
The Ring programming language version 1.10 book - Part 50 of 212
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data

What's hot (20)

PDF
The Ring programming language version 1.5.3 book - Part 40 of 184
PDF
Google App Engine Developer - Day4
PDF
Cache metadata
ODP
Aggregation Framework in MongoDB Overview Part-1
PPT
Spring data iii
PDF
Aggregation Framework MongoDB Days Munich
PDF
Presto in Treasure Data
PDF
Android HttpClient - new slide!
PDF
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
PDF
MariaDB and Clickhouse Percona Live 2019 talk
PDF
The Ring programming language version 1.9 book - Part 49 of 210
PPTX
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
PPTX
Slick: Bringing Scala’s Powerful Features to Your Database Access
PDF
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
PDF
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
PPTX
Apache spark
PDF
Utilizing Powerful Extensions for Analytics and Operations
PDF
Green dao
PDF
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
PPTX
MongoDB World 2016 : Advanced Aggregation
The Ring programming language version 1.5.3 book - Part 40 of 184
Google App Engine Developer - Day4
Cache metadata
Aggregation Framework in MongoDB Overview Part-1
Spring data iii
Aggregation Framework MongoDB Days Munich
Presto in Treasure Data
Android HttpClient - new slide!
Tricks every ClickHouse designer should know, by Robert Hodges, Altinity CEO
MariaDB and Clickhouse Percona Live 2019 talk
The Ring programming language version 1.9 book - Part 49 of 210
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
Slick: Bringing Scala’s Powerful Features to Your Database Access
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Apache spark
Utilizing Powerful Extensions for Analytics and Operations
Green dao
ClickHouse tips and tricks. Webinar slides. By Robert Hodges, Altinity CEO
MongoDB World 2016 : Advanced Aggregation
Ad

Viewers also liked (20)

PDF
Database Schema
KEY
Schema Design with MongoDB
PDF
Clojure presentation
PDF
Database schema handbook for cisco unified icm contact center enterprise & ho...
PDF
FleetDB
PPT
A House Is Not A Home Version 1 3 Minus
PPT
House and home
PPT
Database 2 External Schema
PPTX
PPTX
a house a home
PPT
Best Practices for Database Schema Design
PPTX
C1 Topic 6 House & Home
KEY
Home and House idioms
PPTX
مقدمة في قواعد البيانات
PPSX
Databases قواعد البيانات
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
PPT
أساسيات قواعد البيانات
PPTX
Database schema
DOCX
تخطيط قاعده بيانات مدرسه
DOCX
اسئلة قواعد البيانات
Database Schema
Schema Design with MongoDB
Clojure presentation
Database schema handbook for cisco unified icm contact center enterprise & ho...
FleetDB
A House Is Not A Home Version 1 3 Minus
House and home
Database 2 External Schema
a house a home
Best Practices for Database Schema Design
C1 Topic 6 House & Home
Home and House idioms
مقدمة في قواعد البيانات
Databases قواعد البيانات
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
أساسيات قواعد البيانات
Database schema
تخطيط قاعده بيانات مدرسه
اسئلة قواعد البيانات
Ad

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

PDF
Kief Morris - Infrastructure is terrible
PDF
Type safe embedded domain-specific languages
PDF
Infrastructure-as-code: bridging the gap between Devs and Ops
PDF
Immutable Deployments with AWS CloudFormation and AWS Lambda
PDF
Infrastructure as code terraformujeme cloud
PPTX
MongoDB World 2018: Keynote
PDF
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
PDF
Learn Cloud-Native .NET: Core Configuration Fundamentals with Steeltoe
PPTX
Google apps script database abstraction exposed version
PDF
Cutting through the fog of cloud
PDF
SF Elixir Meetup - RethinkDB
PDF
Atmosphere Conference 2015: Taming the Modern Datacenter
PPTX
Capture, record, clip, embed and play, search: video from newbie to ninja
PDF
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
PDF
Amazon Web Services for PHP Developers
PDF
Cutting Edge Data Processing with PHP & XQuery
PPT
Distributed Queries in IDS: New features.
PDF
Ajax Performance Tuning and Best Practices
KEY
Couchdb: No SQL? No driver? No problem
PDF
OSDC 2012 | Scaling with MongoDB by Ross Lawley
Kief Morris - Infrastructure is terrible
Type safe embedded domain-specific languages
Infrastructure-as-code: bridging the gap between Devs and Ops
Immutable Deployments with AWS CloudFormation and AWS Lambda
Infrastructure as code terraformujeme cloud
MongoDB World 2018: Keynote
PuppetDB: A Single Source for Storing Your Puppet Data - PUG NY
Learn Cloud-Native .NET: Core Configuration Fundamentals with Steeltoe
Google apps script database abstraction exposed version
Cutting through the fog of cloud
SF Elixir Meetup - RethinkDB
Atmosphere Conference 2015: Taming the Modern Datacenter
Capture, record, clip, embed and play, search: video from newbie to ninja
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
Amazon Web Services for PHP Developers
Cutting Edge Data Processing with PHP & XQuery
Distributed Queries in IDS: New features.
Ajax Performance Tuning and Best Practices
Couchdb: No SQL? No driver? No problem
OSDC 2012 | Scaling with MongoDB by Ross Lawley

Recently uploaded (20)

PDF
Approach and Philosophy of On baking technology
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
KodekX | Application Modernization Development
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
cuic standard and advanced reporting.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
Approach and Philosophy of On baking technology
MYSQL Presentation for SQL database connectivity
Understanding_Digital_Forensics_Presentation.pptx
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Digital-Transformation-Roadmap-for-Companies.pptx
The AUB Centre for AI in Media Proposal.docx
Reach Out and Touch Someone: Haptics and Empathic Computing
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
KodekX | Application Modernization Development
Advanced methodologies resolving dimensionality complications for autism neur...
sap open course for s4hana steps from ECC to s4
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
cuic standard and advanced reporting.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Review of recent advances in non-invasive hemoglobin estimation

FleetDB: A Schema-Free Database in Clojure