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

         Mark McGranaghan


           January 8, 2010
Motivation


Walkthrough


Implementation


QA
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!
Thanks for listening!

    Questions?
http://FleetDB.org

http://github.com/mmcgrana

More Related Content

PDF
FleetDB: A Schema-Free Database in Clojure
PPTX
MongoDB - Aggregation Pipeline
PDF
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
PPT
SharePoint Administration with PowerShell
PPTX
MongoDB Aggregation
PPTX
Getting Started with MongoDB and NodeJS
PDF
The Ring programming language version 1.10 book - Part 50 of 212
PDF
The Ring programming language version 1.5.3 book - Part 40 of 184
FleetDB: A Schema-Free Database in Clojure
MongoDB - Aggregation Pipeline
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
SharePoint Administration with PowerShell
MongoDB Aggregation
Getting Started with MongoDB and NodeJS
The Ring programming language version 1.10 book - Part 50 of 212
The Ring programming language version 1.5.3 book - Part 40 of 184

What's hot (20)

PDF
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
PDF
Cache metadata
PDF
Presto in Treasure Data
PDF
Google App Engine Developer - Day4
PPTX
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
ODP
Aggregation Framework in MongoDB Overview Part-1
PDF
Aggregation Framework MongoDB Days Munich
PDF
The Ring programming language version 1.9 book - Part 49 of 210
PPTX
Slick: Bringing Scala’s Powerful Features to Your Database Access
PDF
MariaDB and Clickhouse Percona Live 2019 talk
PDF
Utilizing Powerful Extensions for Analytics and Operations
PDF
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
PDF
Android HttpClient - new slide!
PDF
Green dao
PDF
Green dao
PDF
Terraforming the Kubernetes Land
PPTX
Getting started with Elasticsearch and .NET
PDF
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
ODP
MongoDB San Francisco DrupalCon 2010
PDF
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
Cache metadata
Presto in Treasure Data
Google App Engine Developer - Day4
apidays LIVE Australia 2020 - Building distributed systems on the shoulders o...
Aggregation Framework in MongoDB Overview Part-1
Aggregation Framework MongoDB Days Munich
The Ring programming language version 1.9 book - Part 49 of 210
Slick: Bringing Scala’s Powerful Features to Your Database Access
MariaDB and Clickhouse Percona Live 2019 talk
Utilizing Powerful Extensions for Analytics and Operations
Temporary Cache Assistance (Transients API): WordCamp Phoenix 2014
Android HttpClient - new slide!
Green dao
Green dao
Terraforming the Kubernetes Land
Getting started with Elasticsearch and .NET
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
MongoDB San Francisco DrupalCon 2010
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Ad

Viewers also liked (11)

PDF
Clojure presentation
PDF
FleetDB
PDF
HBase Schema Design - HBase-Con 2012
KEY
Schema Design with MongoDB
PDF
Freebase Schema
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
DOCX
Employee management system1
PPTX
service quality-models-ppt
PPTX
Services Marketing - Service Quality GAPS Model
PPTX
Medical Store Management System Software Engineering Project
PPSX
Employee Management System
Clojure presentation
FleetDB
HBase Schema Design - HBase-Con 2012
Schema Design with MongoDB
Freebase Schema
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
Employee management system1
service quality-models-ppt
Services Marketing - Service Quality GAPS Model
Medical Store Management System Software Engineering Project
Employee Management System
Ad

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

PDF
Microservices in Clojure
PPTX
Python Ireland Conference 2016 - Python and MongoDB Workshop
PDF
Big Data for Mobile
PDF
Extend db
PDF
NoSQL and CouchDB
PPTX
I say NoSQL you say what
PDF
The productivity brought by Clojure
KEY
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
PPT
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
PDF
learn you some erlang - chap 9 to chap10
PPTX
Webinar: MongoDB and Polyglot Persistence Architecture
PDF
MongoDB @ SourceForge
PPTX
NOSQL and MongoDB Database
PPTX
No sql solutions - 공개용
PDF
Datastores
PPTX
Introduction to Polyglot Persistence
KEY
NoSQL: Why, When, and How
PDF
Elastic Search
PDF
Testing stateful, concurrent, and async systems using test.check
KEY
Taming NoSQL with Spring Data
Microservices in Clojure
Python Ireland Conference 2016 - Python and MongoDB Workshop
Big Data for Mobile
Extend db
NoSQL and CouchDB
I say NoSQL you say what
The productivity brought by Clojure
Scala Days 2011 - Rogue: A Type-Safe DSL for MongoDB
Architecture | Busy Java Developers Guide to NoSQL | Ted Neward
learn you some erlang - chap 9 to chap10
Webinar: MongoDB and Polyglot Persistence Architecture
MongoDB @ SourceForge
NOSQL and MongoDB Database
No sql solutions - 공개용
Datastores
Introduction to Polyglot Persistence
NoSQL: Why, When, and How
Elastic Search
Testing stateful, concurrent, and async systems using test.check
Taming NoSQL with Spring Data

More from elliando dias (20)

PDF
Clojurescript slides
PDF
Why you should be excited about ClojureScript
PDF
Functional Programming with Immutable Data Structures
PPT
Nomenclatura e peças de container
PDF
Geometria Projetiva
PDF
Polyglot and Poly-paradigm Programming for Better Agility
PDF
Javascript Libraries
PDF
How to Make an Eight Bit Computer and Save the World!
PDF
Ragel talk
PDF
A Practical Guide to Connecting Hardware to the Web
PDF
Introdução ao Arduino
PDF
Minicurso arduino
PDF
Incanter Data Sorcery
PDF
PDF
Fab.in.a.box - Fab Academy: Machine Design
PDF
The Digital Revolution: Machines that makes
PDF
Hadoop + Clojure
PDF
Hadoop - Simple. Scalable.
PDF
Hadoop and Hive Development at Facebook
PDF
Multi-core Parallelization in Clojure - a Case Study
Clojurescript slides
Why you should be excited about ClojureScript
Functional Programming with Immutable Data Structures
Nomenclatura e peças de container
Geometria Projetiva
Polyglot and Poly-paradigm Programming for Better Agility
Javascript Libraries
How to Make an Eight Bit Computer and Save the World!
Ragel talk
A Practical Guide to Connecting Hardware to the Web
Introdução ao Arduino
Minicurso arduino
Incanter Data Sorcery
Fab.in.a.box - Fab Academy: Machine Design
The Digital Revolution: Machines that makes
Hadoop + Clojure
Hadoop - Simple. Scalable.
Hadoop and Hive Development at Facebook
Multi-core Parallelization in Clojure - a Case Study

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPT
Teaching material agriculture food technology
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Empathic Computing: Creating Shared Understanding
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Approach and Philosophy of On baking technology
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Machine learning based COVID-19 study performance prediction
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Teaching material agriculture food technology
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
“AI and Expert System Decision Support & Business Intelligence Systems”
Empathic Computing: Creating Shared Understanding
Diabetes mellitus diagnosis method based random forest with bat algorithm
Programs and apps: productivity, graphics, security and other tools
Approach and Philosophy of On baking technology
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Encapsulation_ Review paper, used for researhc scholars
MIND Revenue Release Quarter 2 2025 Press Release
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
Machine learning based COVID-19 study performance prediction

FleetDB A Schema-Free Database in Clojure