際際滷

際際滷Share a Scribd company logo
Functional Database
Strategies
Scal脱 by the Bay 2016
YesQL
by Jason Swartz
@swartzrock
Functional Database Strategies
Functional Database
Strategies
Step One
Buy A Functional Database
Silly! Databases Are
mutable, not
functional!
Well?
Arentthey?
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
Lets Talk About
Immutable Tables
Functional Database Strategies
Functional Database Strategies
Create-Read-
Update-Delete
GET /issues
GET /issues/{id}
POST /issues
PUT /issues/{id}
Issue Endpoints
How Do These Events
Affect The Database?
1. POST /issues title=Config ELB
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
Not Bad.
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
Do You Know How We Got Here?
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
Do You Know How We Got Here?
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
Do You Know How We Got Here?
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
Why is assignee NULL?
Mutable Table Rows
Lose History
Immutable Table
Rows KeepTheir History
Lets Try To
Lock Down
Our State
1. POST /issues title=Config ELB
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:19 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:19 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
1. GET /issues/1
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:19 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
Tables Are Mutable,
But Table Rows Should Be
Immutable
In Other Words, Tables
Should Be
Append-Only
How Do You Make An
Append-Only
Table?
One: Dont Let Your DB
User Make
Changes
Grant select, insert on
issues to my-db-user;
-- tested on Postgresql
Thank You!
Goodbye!
Two: Pick The Right
Columns
1. GET /issues/1
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:19 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | NULL | true |
+------+-------------+------------+----------+-------+
create table issues (
id serial,
created timestamp default now(),
issue_id int default nextval(iseq),
title text,
assignee int,
done boolean default false
)
1. GET /issues/1
+------+-------------+------------+------------+----------+-------+
| id | created | issue_id | title | assignee | done |
+------+-------------+------------+------------+----------+-------+
| 1 | 09-18 18:13 | 1 | Config ELB | NULL | false |
+------+-------------+------------+------------+----------+-------+
| 2 | 09-18 18:16 | 1 | Config ELB | 10 | false |
+------+-------------+------------+------------+----------+-------+
| 3 | 09-18 18:19 | 1 | Config ELB | NULL | false |
+------+-------------+------------+------------+----------+-------+
+------+-------------+------------+------------+----------+-------+
| 4 | 09-18 18:24 | 1 | Config ELB | NULL | true |
+------+-------------+------------+------------+----------+-------+
select * from issues
where issue_id = :issue_id
order by id desc limit 1;
Thats The Basics Of
Immutability
In Table Rows
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
SQL:2003 expands
Groups into Windows
Works Great In
Postgresql
 Aggregation functions, eg sum(), rank(), avg()
 Window definitions with over()
 Grouping with partition by, order
Window Functions
+------+------------+------------+----------+-------+
| id | issue_id | title | assignee | done |
+------+------------+------------+----------+-------+
| 1 | 1 | Config ELB | NULL | false |
+------+------------+------------+----------+-------+
| 2 | 1 | Config ELB | 10 | false |
+------+------------+------------+----------+-------+
| 3 | 2 | Bug to fix | 11 | false |
+------+------------+------------+----------+-------+
| 4 | 2 | Bug to fix | 11 | true |
+------+------------+------------+----------+-------+
+------+------------+------------+----------+-------+
| id | issue_id | title | assignee | done |
+------+------------+------------+----------+-------+
| 1 | 1 | Config ELB | NULL | false |
+------+------------+------------+----------+-------+
| 2 | 1 | Config ELB | 10 | false |
+------+------------+------------+----------+-------+
| 3 | 2 | Bug to fix | 11 | false |
+------+------------+------------+----------+-------+
| 4 | 2 | Bug to fix | 11 | true |
+------+------------+------------+----------+-------+
with latest_issues as (
select *, row_number() over (
partition by issue_id
order by id
desc
)
from issues where created > now() - interval '7 day'
)
select * from latest_issues where row_number = 1
with latest_issues as (
select *, row_number() over (
partition by issue_id
order by id
desc
)
from issues where created > now() - interval '7 day'
)
select * from latest_issues where row_number = 1
with latest_issues as (
select *, row_number() over (
partition by issue_id
order by id
desc
)
from issues where created > now() - interval '7 day'
)
select * from latest_issues where row_number = 1
with latest_issues as (
select *, row_number() over (
partition by issue_id
order by id
desc
)
from issues where created > now() - interval '7 day'
)
select * from latest_issues where row_number = 1
+------+------------+------------+----------+-------+------------+
| id | issue_id | title | assignee | done | row_number |
+------+------------+------------+----------+-------+------------+
| 1 | 1 | Config ELB | NULL | false | 2 |
+------+------------+------------+----------+-------+------------+
| 2 | 1 | Config ELB | 10 | false | 1 |
+------+------------+------------+----------+-------+------------+
| 3 | 2 | Bug to fix | 11 | false | 2 |
+------+------------+------------+----------+-------+------------+
| 4 | 2 | Bug to fix | 11 | true | 1 |
+------+------------+------------+----------+-------+------------+
+------+------------+------------+----------+-------+------------+
| id | issue_id | title | assignee | done | row_number |
+------+------------+------------+----------+-------+------------+
| 1 | 1 | Config ELB | NULL | false | 2 |
+------+------------+------------+----------+-------+------------+
| 2 | 1 | Config ELB | 10 | false | 1 |
+------+------------+------------+----------+-------+------------+
| 3 | 2 | Bug to fix | 11 | false | 2 |
+------+------------+------------+----------+-------+------------+
| 4 | 2 | Bug to fix | 11 | true | 1 |
+------+------------+------------+----------+-------+------------+
+------+------------+------------+----------+-------+------------+
| id | issue_id | title | assignee | done | row_number |
+------+------------+------------+----------+-------+------------+
| 1 | 1 | Config ELB | NULL | false | 2 |
+------+------------+------------+----------+-------+------------+
| 2 | 1 | Config ELB | 10 | false | 1 |
+------+------------+------------+----------+-------+------------+
| 3 | 2 | Bug to fix | 11 | false | 2 |
+------+------------+------------+----------+-------+------------+
| 4 | 2 | Bug to fix | 11 | true | 1 |
+------+------------+------------+----------+-------+------------+
That Was
Window
Functions
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
You Know How To Maintain
State
Do We Still Need
State?
Lets Talk About
Event-Sourcing
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | 10 | true |
+------+-------------+------------+----------+-------+
1. POST /issues title=Config ELB
2. PUT /issues/1 assignee=10
3. PUT /issues/1 done=true
+------+-------------+------------+----------+-------+
| id | updated | title | assignee | done |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:13 | Config ELB | NULL | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:16 | Config ELB | 10 | false |
+------+-------------+------------+----------+-------+
| 1 | 09-18 18:24 | Config ELB | 10 | true |
+------+-------------+------------+----------+-------+
Events
States
Functional Database Strategies
Functional Database Strategies
Functional Database Strategies
Functional Database Strategies
Now Were Storing
Events,
Not States
create table issue_events (
id serial,
created timestamp default now(),
issue_id int default nextval(iseq),
originator text,
payload text
)
1. POST /issue/1/event Originator: 4a48239-8a..
payload=<Update val=done=true>
+----+-------------+----------+------------+---------+
| id | created | issue_id | originator | payload |
+----+-------------+----------+------------+---------+
| 14 | 09-18 18:50 | 1 | 4a482... | <...> |
+----+-------------+----------+------------+---------+
Create Events And
Simulate The State
1. Create-Issue
Issue(Config ELB, null, false);
Real Events
Virtual States
1. Create-Issue
2. Assign-Issue
Issue(Config ELB, 10, false);
Real Events
Virtual States
1. Create-Issue
2. Assign-Issue
3. Complete-Issue
Issue(Config ELB, 10, true);
Real Events
Virtual States
So Why Use
Event-Sourcing?
1. High Write Performance
2. Potential for Command/Query Separation
3. Auditable
4. Replayable
5. Undo-able
6. Monitorable
Reasons For Event-Sourcing
Its Like Having Control
Over The Versions Of
Your State Changes
Its Like Having Control
Over The Versions Of
Your Data
Its Like Git
For Your Data
1. Frankly, Its Weird
2. Requires Events. No Events, No Event-Sourcing.
3. As Of November 2016, Its Still Non-Standard
Reasons Against Event-Sourcing
Wait! Were
Scala
developers!
Who Cares About Being
Non-Standard?
That About Sums Up
Event Sourcing
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
1. Immutable Rows
2. Window Functions
3. Events, Not State
4. DB Interactions
Agenda
Remember That Your
Database
is mutable.
Avoid Sharing
Your State
 Avoid shared mutable SESSIONS
 Avoid shared mutable CURSORS
 Mutating state? Cool! But MODEL IT FIRST
 Execute state changes at THE EDGE
Safe Database Interactions
Doobie
A Typelevel Project
Are these steps? Or a Monad?
Functional Database Strategies
That About Sums Up
Database
Interactions
Okay, Actually Thats The
Entire Talk
Unless Theres More Time
Functional Database
Strategies
Scal脱 by the Bay 2016
by Jason Swartz
@swartzrock
Thank You
For Attending
Fin
THIS SPACE
LEFT BLANK

More Related Content

Similar to Functional Database Strategies (20)

Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016
Jason Swartz
M|18 User Defined Function
M|18 User Defined FunctionM|18 User Defined Function
M|18 User Defined Function
MariaDB plc
ANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gemANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gem
Sergey Petrunya
New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12
Sergey Petrunya
Explain2
Explain2Explain2
Explain2
Anis Berejeb
Workshop 20140522 BigQuery Implementation
Workshop 20140522   BigQuery ImplementationWorkshop 20140522   BigQuery Implementation
Workshop 20140522 BigQuery Implementation
Simon Su
The two little bugs that almost brought down Booking.com
The two little bugs that almost brought down Booking.comThe two little bugs that almost brought down Booking.com
The two little bugs that almost brought down Booking.com
Jean-Fran巽ois Gagn辿
Percona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuningPercona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuning
Sergey Petrunya
Optimizing Queries Using Window Functions
Optimizing Queries Using Window FunctionsOptimizing Queries Using Window Functions
Optimizing Queries Using Window Functions
I Goo Lee
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
BigQuery implementation
BigQuery implementationBigQuery implementation
BigQuery implementation
Simon Su
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
MariaDB: Engine Independent Table Statistics, including histograms
MariaDB: Engine Independent Table Statistics, including histogramsMariaDB: Engine Independent Table Statistics, including histograms
MariaDB: Engine Independent Table Statistics, including histograms
Sergey Petrunya
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
KISHOYIANKISH
Adapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cAdapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12c
Mauro Pagano
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with Galera
Sveta Smirnova
MySQL SQL Tutorial
MySQL SQL TutorialMySQL SQL Tutorial
MySQL SQL Tutorial
Chien Chung Shen
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performance
MariaDB plc
Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016Microservices Tutorial Session at JavaOne 2016
Microservices Tutorial Session at JavaOne 2016
Jason Swartz
M|18 User Defined Function
M|18 User Defined FunctionM|18 User Defined Function
M|18 User Defined Function
MariaDB plc
ANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gemANALYZE for Statements - MariaDB's hidden gem
ANALYZE for Statements - MariaDB's hidden gem
Sergey Petrunya
New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12New optimizer features in MariaDB releases before 10.12
New optimizer features in MariaDB releases before 10.12
Sergey Petrunya
Workshop 20140522 BigQuery Implementation
Workshop 20140522   BigQuery ImplementationWorkshop 20140522   BigQuery Implementation
Workshop 20140522 BigQuery Implementation
Simon Su
The two little bugs that almost brought down Booking.com
The two little bugs that almost brought down Booking.comThe two little bugs that almost brought down Booking.com
The two little bugs that almost brought down Booking.com
Jean-Fran巽ois Gagn辿
Percona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuningPercona live-2012-optimizer-tuning
Percona live-2012-optimizer-tuning
Sergey Petrunya
Optimizing Queries Using Window Functions
Optimizing Queries Using Window FunctionsOptimizing Queries Using Window Functions
Optimizing Queries Using Window Functions
I Goo Lee
MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015MySQL 5.7 Tutorial Dutch PHP Conference 2015
MySQL 5.7 Tutorial Dutch PHP Conference 2015
Dave Stokes
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015MySQL 5.7. Tutorial - Dutch PHP Conference 2015
MySQL 5.7. Tutorial - Dutch PHP Conference 2015
Dave Stokes
BigQuery implementation
BigQuery implementationBigQuery implementation
BigQuery implementation
Simon Su
Applied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System PresentationApplied Partitioning And Scaling Your Database System Presentation
Applied Partitioning And Scaling Your Database System Presentation
Richard Crowley
MariaDB: Engine Independent Table Statistics, including histograms
MariaDB: Engine Independent Table Statistics, including histogramsMariaDB: Engine Independent Table Statistics, including histograms
MariaDB: Engine Independent Table Statistics, including histograms
Sergey Petrunya
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
4. Data Manipulation.ppt
4. Data Manipulation.ppt4. Data Manipulation.ppt
4. Data Manipulation.ppt
KISHOYIANKISH
Adapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12cAdapting to Adaptive Plans on 12c
Adapting to Adaptive Plans on 12c
Mauro Pagano
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with Galera
Sveta Smirnova
How to use histograms to get better performance
How to use histograms to get better performanceHow to use histograms to get better performance
How to use histograms to get better performance
MariaDB plc

More from Jason Swartz (7)

High Performance Serverless Functions in Scala
High Performance Serverless Functions in ScalaHigh Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala
Jason Swartz
Everyone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for MicroservicesEveryone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for Microservices
Jason Swartz
Everyone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messagingEveryone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messaging
Jason Swartz
Enterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of BarcelonaEnterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of Barcelona
Jason Swartz
Build Enterprise APIs WIth Ease (And Scala)
Build Enterprise APIs WIth Ease (And Scala)Build Enterprise APIs WIth Ease (And Scala)
Build Enterprise APIs WIth Ease (And Scala)
Jason Swartz
OSCON - Get Started Developing With Scala
OSCON - Get Started Developing With ScalaOSCON - Get Started Developing With Scala
OSCON - Get Started Developing With Scala
Jason Swartz
APICon SF - Enterprise APIs With Ease
APICon SF - Enterprise APIs With EaseAPICon SF - Enterprise APIs With Ease
APICon SF - Enterprise APIs With Ease
Jason Swartz
High Performance Serverless Functions in Scala
High Performance Serverless Functions in ScalaHigh Performance Serverless Functions in Scala
High Performance Serverless Functions in Scala
Jason Swartz
Everyone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for MicroservicesEveryone's Guide to States, Events and Async-Messaging for Microservices
Everyone's Guide to States, Events and Async-Messaging for Microservices
Jason Swartz
Everyone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messagingEveryone's guide to event sourcing and async-messaging
Everyone's guide to event sourcing and async-messaging
Jason Swartz
Enterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of BarcelonaEnterprise APIs With Ease - Scala Developers of Barcelona
Enterprise APIs With Ease - Scala Developers of Barcelona
Jason Swartz
Build Enterprise APIs WIth Ease (And Scala)
Build Enterprise APIs WIth Ease (And Scala)Build Enterprise APIs WIth Ease (And Scala)
Build Enterprise APIs WIth Ease (And Scala)
Jason Swartz
OSCON - Get Started Developing With Scala
OSCON - Get Started Developing With ScalaOSCON - Get Started Developing With Scala
OSCON - Get Started Developing With Scala
Jason Swartz
APICon SF - Enterprise APIs With Ease
APICon SF - Enterprise APIs With EaseAPICon SF - Enterprise APIs With Ease
APICon SF - Enterprise APIs With Ease
Jason Swartz

Recently uploaded (20)

Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...
UHV UNIT-5  IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...UHV UNIT-5  IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...
arivazhaganrajangam
BUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptxBUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptx
greeshmadj0
"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
BCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdfBCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
Chapter 1- Introduction-chemical bonding.pptx
Chapter 1- Introduction-chemical bonding.pptxChapter 1- Introduction-chemical bonding.pptx
Chapter 1- Introduction-chemical bonding.pptx
venomalvi2
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
HardeepZinta2
chapter 2 combustion engineering for second semester
chapter 2 combustion engineering for second semesterchapter 2 combustion engineering for second semester
chapter 2 combustion engineering for second semester
MeleseLegamo
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptxBCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
VENKATESHBHAT25
he ne laser description regarding the no
he ne laser description regarding the nohe ne laser description regarding the no
he ne laser description regarding the no
rjraj1886
Final Round of technical quiz on Chandrayaan
Final Round of technical quiz on ChandrayaanFinal Round of technical quiz on Chandrayaan
Final Round of technical quiz on Chandrayaan
kamesh sonti
REVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODS
REVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODSREVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODS
REVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODS
gerogepatton
22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS
22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS
22PCOAM16 ML UNIT 2 NOTES & QB QUESTION WITH ANSWERS
Guru Nanak Technical Institutions
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-8-2025 FINAL ver4...
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-8-2025 FINAL ver4...YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-8-2025 FINAL ver4...
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-8-2025 FINAL ver4...
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Alberto Lorenzo
Introduction to CLoud Computing Technologies
Introduction to CLoud Computing TechnologiesIntroduction to CLoud Computing Technologies
Introduction to CLoud Computing Technologies
cloudlab1
Tantrayukti.pptx. It is a ppt on tantrayukti
Tantrayukti.pptx.  It is a ppt on tantrayuktiTantrayukti.pptx.  It is a ppt on tantrayukti
Tantrayukti.pptx. It is a ppt on tantrayukti
AnuragKumar682871
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptxUHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
arivazhaganrajangam
Network analysis and synthesis CH 03-pptx.pptx
Network analysis and synthesis  CH 03-pptx.pptxNetwork analysis and synthesis  CH 03-pptx.pptx
Network analysis and synthesis CH 03-pptx.pptx
GetahunShankoKefeni
P_Type_N_Type_Semiconductors_Detailed.pptx
P_Type_N_Type_Semiconductors_Detailed.pptxP_Type_N_Type_Semiconductors_Detailed.pptx
P_Type_N_Type_Semiconductors_Detailed.pptx
VinayPaul17
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
Self-Compacting Concrete: Composition, Properties, and Applications in Modern...
NIT SILCHAR
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...
UHV UNIT-5  IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...UHV UNIT-5  IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...
UHV UNIT-5 IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON P...
arivazhaganrajangam
BUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptxBUILD WITH AI for GDG on campus MVJCE.pptx
BUILD WITH AI for GDG on campus MVJCE.pptx
greeshmadj0
"Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications""Introduction to VLSI Design: Concepts and Applications"
"Introduction to VLSI Design: Concepts and Applications"
GtxDriver
BCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdfBCS401 ADA First IA Test Question Bank.pdf
BCS401 ADA First IA Test Question Bank.pdf
VENKATESHBHAT25
Chapter 1- Introduction-chemical bonding.pptx
Chapter 1- Introduction-chemical bonding.pptxChapter 1- Introduction-chemical bonding.pptx
Chapter 1- Introduction-chemical bonding.pptx
venomalvi2
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
he Wright brothers, Orville and Wilbur, invented and flew the first successfu...
HardeepZinta2
chapter 2 combustion engineering for second semester
chapter 2 combustion engineering for second semesterchapter 2 combustion engineering for second semester
chapter 2 combustion engineering for second semester
MeleseLegamo
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptxBCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
VENKATESHBHAT25
he ne laser description regarding the no
he ne laser description regarding the nohe ne laser description regarding the no
he ne laser description regarding the no
rjraj1886
Final Round of technical quiz on Chandrayaan
Final Round of technical quiz on ChandrayaanFinal Round of technical quiz on Chandrayaan
Final Round of technical quiz on Chandrayaan
kamesh sonti
REVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODS
REVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODSREVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODS
REVOLUTIONIZING LEAD QUALIFICATION: THE POWER OF LLMS OVER TRADITIONAL METHODS
gerogepatton
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Reinventando el CD_ Unificando Aplicaciones e Infraestructura con Crossplane-...
Alberto Lorenzo
Introduction to CLoud Computing Technologies
Introduction to CLoud Computing TechnologiesIntroduction to CLoud Computing Technologies
Introduction to CLoud Computing Technologies
cloudlab1
Tantrayukti.pptx. It is a ppt on tantrayukti
Tantrayukti.pptx.  It is a ppt on tantrayuktiTantrayukti.pptx.  It is a ppt on tantrayukti
Tantrayukti.pptx. It is a ppt on tantrayukti
AnuragKumar682871
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptxUHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
UHV UNIT-3 HARMONY IN THE FAMILY AND SOCIETY.pptx
arivazhaganrajangam
Network analysis and synthesis CH 03-pptx.pptx
Network analysis and synthesis  CH 03-pptx.pptxNetwork analysis and synthesis  CH 03-pptx.pptx
Network analysis and synthesis CH 03-pptx.pptx
GetahunShankoKefeni
P_Type_N_Type_Semiconductors_Detailed.pptx
P_Type_N_Type_Semiconductors_Detailed.pptxP_Type_N_Type_Semiconductors_Detailed.pptx
P_Type_N_Type_Semiconductors_Detailed.pptx
VinayPaul17

Functional Database Strategies

  • 6. Step One Buy A Functional Database
  • 9. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 10. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 15. GET /issues GET /issues/{id} POST /issues PUT /issues/{id} Issue Endpoints
  • 16. How Do These Events Affect The Database?
  • 17. 1. POST /issues title=Config ELB +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+
  • 18. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+
  • 19. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+
  • 20. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+ Not Bad.
  • 21. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+ Do You Know How We Got Here?
  • 22. +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+ Do You Know How We Got Here?
  • 23. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+ Do You Know How We Got Here?
  • 24. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+ Why is assignee NULL?
  • 27. Lets Try To Lock Down Our State
  • 28. 1. POST /issues title=Config ELB +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+
  • 29. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+
  • 30. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:19 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+
  • 31. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:19 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+
  • 32. 1. GET /issues/1 +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:19 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+
  • 33. Tables Are Mutable, But Table Rows Should Be Immutable
  • 34. In Other Words, Tables Should Be Append-Only
  • 35. How Do You Make An Append-Only Table?
  • 36. One: Dont Let Your DB User Make Changes
  • 37. Grant select, insert on issues to my-db-user; -- tested on Postgresql
  • 39. Two: Pick The Right Columns
  • 40. 1. GET /issues/1 +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:19 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | NULL | true | +------+-------------+------------+----------+-------+
  • 41. create table issues ( id serial, created timestamp default now(), issue_id int default nextval(iseq), title text, assignee int, done boolean default false )
  • 42. 1. GET /issues/1 +------+-------------+------------+------------+----------+-------+ | id | created | issue_id | title | assignee | done | +------+-------------+------------+------------+----------+-------+ | 1 | 09-18 18:13 | 1 | Config ELB | NULL | false | +------+-------------+------------+------------+----------+-------+ | 2 | 09-18 18:16 | 1 | Config ELB | 10 | false | +------+-------------+------------+------------+----------+-------+ | 3 | 09-18 18:19 | 1 | Config ELB | NULL | false | +------+-------------+------------+------------+----------+-------+ +------+-------------+------------+------------+----------+-------+ | 4 | 09-18 18:24 | 1 | Config ELB | NULL | true | +------+-------------+------------+------------+----------+-------+
  • 43. select * from issues where issue_id = :issue_id order by id desc limit 1;
  • 44. Thats The Basics Of Immutability In Table Rows
  • 45. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 46. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 49. Aggregation functions, eg sum(), rank(), avg() Window definitions with over() Grouping with partition by, order Window Functions
  • 50. +------+------------+------------+----------+-------+ | id | issue_id | title | assignee | done | +------+------------+------------+----------+-------+ | 1 | 1 | Config ELB | NULL | false | +------+------------+------------+----------+-------+ | 2 | 1 | Config ELB | 10 | false | +------+------------+------------+----------+-------+ | 3 | 2 | Bug to fix | 11 | false | +------+------------+------------+----------+-------+ | 4 | 2 | Bug to fix | 11 | true | +------+------------+------------+----------+-------+
  • 51. +------+------------+------------+----------+-------+ | id | issue_id | title | assignee | done | +------+------------+------------+----------+-------+ | 1 | 1 | Config ELB | NULL | false | +------+------------+------------+----------+-------+ | 2 | 1 | Config ELB | 10 | false | +------+------------+------------+----------+-------+ | 3 | 2 | Bug to fix | 11 | false | +------+------------+------------+----------+-------+ | 4 | 2 | Bug to fix | 11 | true | +------+------------+------------+----------+-------+
  • 52. with latest_issues as ( select *, row_number() over ( partition by issue_id order by id desc ) from issues where created > now() - interval '7 day' ) select * from latest_issues where row_number = 1
  • 53. with latest_issues as ( select *, row_number() over ( partition by issue_id order by id desc ) from issues where created > now() - interval '7 day' ) select * from latest_issues where row_number = 1
  • 54. with latest_issues as ( select *, row_number() over ( partition by issue_id order by id desc ) from issues where created > now() - interval '7 day' ) select * from latest_issues where row_number = 1
  • 55. with latest_issues as ( select *, row_number() over ( partition by issue_id order by id desc ) from issues where created > now() - interval '7 day' ) select * from latest_issues where row_number = 1
  • 56. +------+------------+------------+----------+-------+------------+ | id | issue_id | title | assignee | done | row_number | +------+------------+------------+----------+-------+------------+ | 1 | 1 | Config ELB | NULL | false | 2 | +------+------------+------------+----------+-------+------------+ | 2 | 1 | Config ELB | 10 | false | 1 | +------+------------+------------+----------+-------+------------+ | 3 | 2 | Bug to fix | 11 | false | 2 | +------+------------+------------+----------+-------+------------+ | 4 | 2 | Bug to fix | 11 | true | 1 | +------+------------+------------+----------+-------+------------+
  • 57. +------+------------+------------+----------+-------+------------+ | id | issue_id | title | assignee | done | row_number | +------+------------+------------+----------+-------+------------+ | 1 | 1 | Config ELB | NULL | false | 2 | +------+------------+------------+----------+-------+------------+ | 2 | 1 | Config ELB | 10 | false | 1 | +------+------------+------------+----------+-------+------------+ | 3 | 2 | Bug to fix | 11 | false | 2 | +------+------------+------------+----------+-------+------------+ | 4 | 2 | Bug to fix | 11 | true | 1 | +------+------------+------------+----------+-------+------------+
  • 58. +------+------------+------------+----------+-------+------------+ | id | issue_id | title | assignee | done | row_number | +------+------------+------------+----------+-------+------------+ | 1 | 1 | Config ELB | NULL | false | 2 | +------+------------+------------+----------+-------+------------+ | 2 | 1 | Config ELB | 10 | false | 1 | +------+------------+------------+----------+-------+------------+ | 3 | 2 | Bug to fix | 11 | false | 2 | +------+------------+------------+----------+-------+------------+ | 4 | 2 | Bug to fix | 11 | true | 1 | +------+------------+------------+----------+-------+------------+
  • 60. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 61. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 62. You Know How To Maintain State
  • 63. Do We Still Need State?
  • 65. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | 10 | true | +------+-------------+------------+----------+-------+
  • 66. 1. POST /issues title=Config ELB 2. PUT /issues/1 assignee=10 3. PUT /issues/1 done=true +------+-------------+------------+----------+-------+ | id | updated | title | assignee | done | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:13 | Config ELB | NULL | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:16 | Config ELB | 10 | false | +------+-------------+------------+----------+-------+ | 1 | 09-18 18:24 | Config ELB | 10 | true | +------+-------------+------------+----------+-------+ Events States
  • 72. create table issue_events ( id serial, created timestamp default now(), issue_id int default nextval(iseq), originator text, payload text )
  • 73. 1. POST /issue/1/event Originator: 4a48239-8a.. payload=<Update val=done=true> +----+-------------+----------+------------+---------+ | id | created | issue_id | originator | payload | +----+-------------+----------+------------+---------+ | 14 | 09-18 18:50 | 1 | 4a482... | <...> | +----+-------------+----------+------------+---------+
  • 75. 1. Create-Issue Issue(Config ELB, null, false); Real Events Virtual States
  • 76. 1. Create-Issue 2. Assign-Issue Issue(Config ELB, 10, false); Real Events Virtual States
  • 77. 1. Create-Issue 2. Assign-Issue 3. Complete-Issue Issue(Config ELB, 10, true); Real Events Virtual States
  • 79. 1. High Write Performance 2. Potential for Command/Query Separation 3. Auditable 4. Replayable 5. Undo-able 6. Monitorable Reasons For Event-Sourcing
  • 80. Its Like Having Control Over The Versions Of Your State Changes
  • 81. Its Like Having Control Over The Versions Of Your Data
  • 82. Its Like Git For Your Data
  • 83. 1. Frankly, Its Weird 2. Requires Events. No Events, No Event-Sourcing. 3. As Of November 2016, Its Still Non-Standard Reasons Against Event-Sourcing
  • 85. Who Cares About Being Non-Standard?
  • 86. That About Sums Up Event Sourcing
  • 87. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 88. 1. Immutable Rows 2. Window Functions 3. Events, Not State 4. DB Interactions Agenda
  • 91. Avoid shared mutable SESSIONS Avoid shared mutable CURSORS Mutating state? Cool! But MODEL IT FIRST Execute state changes at THE EDGE Safe Database Interactions
  • 93. Are these steps? Or a Monad?
  • 95. That About Sums Up Database Interactions
  • 96. Okay, Actually Thats The Entire Talk Unless Theres More Time
  • 100. Fin