@rob_rich

Databases in the
Microservices World

by Rob Richardson

  @rob_rich

https://robrich.org/

About Me

Rob Richardson

Rob Richardson is a software craftsman building web properties in ASP.NET and Node, React and Vue. He's a frequent speaker at conferences, user groups, and community events, and a diligent teacher and student of high quality software development. You can find this and other talks on https://robrich.org/presentations and follow him on twitter at @rob_rich.

Application Architecture

... yet usually

Micro-databases

They don't all have to be the same
database vendor or database type.

- Me ... right now

Database Types

Relational Database (SQL)

Pros

Cons

  • Strong schema
  • Table joins
  • Very optimized engine
  • Compatible, familiar syntax
  • Optimized for storage size
    (3rd normal form)
  • Not designed to scale horizontally
  • Vertical scaling gets expensive
  • Best with an ORM
  • Need to migrate schema

Document Databases (NoSQL)

Pros

Cons

  • Distributed
  • No schema:
    • Different documents
      have different fields
  • Denormalized means
    faster reads
  • Denormalized means data duplication
  • SDKs for each language
  • Query language is weird
  • No transactions
  • No joins
  • No schema
    • App assumes a schema
    • Query missing nested field

Graph Databases

Pros

Cons

  • Fast to join across relationships
    E.g. friends of friends
  • Doesn't do other things well
    E.g. cross-table joins are really expensive

Key / Value Databases

Pros

Cons

  • Really fast for "by id" queries
  • Can store different data in each record (schema-less)
  • Can't query by non-key fields:
    It's just a binary blob

Time Series Databases

Pros

Cons

  • Windowing functions are perfect for time-series data
  • Not great for other things

Text Search Databases

Pros

Cons

  • Optimized for word-based text search
  • Schema is added at query time
  • No relationships
  • Stop words
  • Only for text

Object (blob) Stores

Pros

Cons

  • Great for very large things:
    • Videos
    • Log files
    • Backups
  • Can't query by non-id easily:
    E.g. read each file and use another tool to search it

Event Sourcing

Pros

Cons

  • Pub & Sub don't need to be online at the same time
  • Can replay from a point in time
  • Distributed
  • Eventual consistency
  • Compute everything to get current version
  • Must build around duplicate delivery
  • Can't query old data

Column Stores

Pros

Cons

  • Better compression
  • Faster seeks
  • Slower reads

Architectures

Monolith database
Monolith Database
Micro-databases
Micro-databases