---
# System prepended metadata

title: The Superpowers of Event Sourcing

---

# The Superpowers of Event Sourcing

- Fianancial Software
- 20 yrs software development

- Complex Data provides insights and many depend on  it

Scaling with Complex Data 
- is hard


- bad data transformation at scale


traditional data model limit

# Source of True
- hight performing cache
- financial reports say for ticketing  or production company
- auto email for customer notificaition
- all kinds of domain or ui models


## Consistency at Source of Truth

flex vs consist

traditional not good at eventual consistency

## what is event sourcing

- app pattern

HISTORICAL EVENTS (not state based)
past business actions 

## Current State vs Historical Events

event based state transition

## Example: 

- coordinate accross the city
- state based: lossy
- direction record keeps tracing
- event based: lossless

state based:
- quick and direct infomation

event based:
- broad and deep insight
- built-in audit log

## Naming Events as Business Actions

historical event are 
- (O) unambigours event names
helpful for customers, user intentions

ambigous name like updated / created, 
good name example: ItemAddedToCart, ExpiredSubscriptionRenewd,

- VehicleStatus = 'Unavailable' => confusing,
- SeatClass = 'First' => how com ?

INTENT CONFUSED UPDATES

not only loss data, also loss intenttion

## quickly recap

benefit
- flexisiblity
- consistency
- better transformation
- deeper insight

## superpower: shape shifting

in previous example 
1. total distance 
2. total distance OE E (some path)
3. total distance T1-T4
4. Location at T4


## decouple your solution stack

### State Based Model

- Business model
- Code/Design
- Data Schema
- Database plaftform
- infrastructure

need to optimize for  many use caseds
got a lot of problems
code is complicated
type coupling 

### Event Based Model

Event Store
- projects for specific model for 
- e.g. for integration, analytics, performance

## shifting infrastructure

hardware decoupling
- oracle high hardware requirements
- Event Sourced solution
    - project to SQLite insted (IOT device)
Cloud vendor decoupling
ES
    project to multi clouds instead
  
DB decoupling:
- Relational: genral query
- OLAP: multi dinemtional query across huge data set
- in memory: fast perform
- Message Broker: event publishing and integration
- flat file : HTML file for CDN


Data Schema Decoupling:

external system 

ES can duplicate data structure

- migrate away from legacy system
- ES can really help

Business Model Decoupling
- Data model is depent  Business
- business is equally dependent on data model

new business objects and process quickly
chance concept & scale up


## example : optimize display of concert ticket availability

Business model: 
- reduce race condition
- model seats with sections instead
Code/Design
- subscirbe to sales event, in memory counter of availability
- update a cache once not available
Data Schema
- Simple key/value pair for each section#, isAvailable pair
Database Platform
- In-memory key value cache like redis
- Configured for replication for multiple locations
Infrastructure
- Cloud vendor that we're already familiar with

## Recap

- Events as Business Action
- Historical Events

superpower
- Shape shifting
    - ability to change form easily
    - build optimized stack for use case
- Time traveling
    - temporal query
    - retroactive updates

## ES not a silver bullet

should use on complex data that is core to business
- not on simple data with no broad audience

when used properly, it will
- drive cost down
- improve data quality
- perfomance and scalability

Its end goal is
- improve distribution of knowledge
- generate insights to help solve complex problems

## QA

change schema 


