DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Data Engineering
  3. Databases
  4. Java Holiday Calendar (Day 9): Event Sourcing

Java Holiday Calendar (Day 9): Event Sourcing

Event sourcing opens up a new way of looking at your database apps. Turn your database into a record of transactions that you can look back to and restart from.

Per-Åke Minborg user avatar by
Per-Åke Minborg
·
Dec. 09, 16 · Opinion
Like (6)
Save
Tweet
Share
9.81K Views

Join the DZone community and get the full member experience.

Join For Free

Image title

Today's tip is about event sourcing, which is a relatively new way of designing database applications. Instead of seeing the database as a representation of the most current state, we would see it as a system of record for all transactions that ever took place in our applications. 

So, instead of saying "find person 3 and replace that person's salary with whatever it is right now plus $100," we would say "person 3's salary increased by $100." Note the subtle but important distinction. 

If we use the first scheme, then we would know the current salary but not what it was before, by how much it increased and when it increased. The latter scheme, however, allows us to replay all transactions so that we can reproduce all states the application ever had. That's great for when we are hunting bugs. 

Another important property of event sourcing is that we do not need the (expensive) absolute consistency of the underlying database. Instead, we only need to make sure that the order of the events remains consistent over time.

How do we keep track of the most recent value in an event sourcing system when it is changing all the time? Well, we could implement something called a Materialized View that holds the most current state. So, if we have an event table called employee_event,s then we could have a Java class EmployeeView that will continuously replay the events in the employees_event table and distil the fold of all events so that we would actually know what salary person 3 has at the moment.

When the number of events increases, it would be more and more expensive to fast forward all the events — for example, when the application restarts. To combat this drawback, the EmployeeView could create periodic snapshots from which it can be restarted. 

Event sourcing is particularly interesting for applications with a microservice architecture.

Read more about event sourcing on Emil Forslund's blog here and on event sourcing and microservices on eventuate.io here.

Follow the Java Holiday Calendar 2016 with small tips and tricks all the way through the winter holiday season.

Event Java (programming language) Database Calendar (Apple) application System of record Materialized view Scheme (programming language) microservice

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Problems of Cloud Cost Management: A Socio-Technical Analysis
  • Hackerman [Comic]
  • 9 Ways You Can Improve Security Posture
  • Learning by Doing: An HTTP API With Rust

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: