Upgrade to Pro — share decks privately, control downloads, hide ads and more …

James Nugent - Event Store Internals

James Nugent - Event Store Internals

Riga Dev Day

January 30, 2015
Tweet

More Decks by Riga Dev Day

Other Decks in Programming

Transcript

  1. Line Items x n Line Items x n Shopping Cart

    Line Items x n Shipping Information
  2. Shopping Cart Created Added 2 shirts Added 5 pairs of

    socks Removed 1 shirt Checked Out
  3. Since we can rebuild current state from a stream of

    events, storing it is just an optimisation
  4. We can project any structural model from our events by

    applying a different fold operation
  5. Testing • At the Aggregate level: • Given past behaviours

    • When method is called • Then events
  6. Testing • At the Aggregate level: • Given past behaviours

    • When method is called • Then events • And nothing else!

  7. Example Tests [Test] public void MyTest() { new CommandScenarioFor<MilesAccount>(MilesAccount.Factory) .Given(new

    MilesAccountCreated(...), new MilesAddedToAccount(...), new TierPointsAddedToAccount(...)) .When(sut => sut.RecordFlightTaken(...)) .Then(new MilesAddedToAccount(...), new CustomerPromotedToGoldStatus(...), new TierPointPeriodReset(...)) .Assert(); }
  8. Example Test [Test] public void ReviewApproval() { new CommandScenarioFor<Review>(Review.Factory) .Given(new

    ReviewSubmitted(...), new ReviewSentForModeration(...), new ReviewApprovedByModerators(...), new ReviewDisplayOnWebApproved(...)) .When(sut => sut.RecordComplaintFromSubject(...)) .Then(new ReviewDisplayOnWebSuspended(...), new ReviewManualArbitrationProcessRequested(...)) .Assert(); }
  9. It cannot be that one model is optimal for transaction

    processing and all types of queries
  10. Construct read models by applying a left fold to the

    events produced by the write model
  11. • Implements a transaction log for event sourced systems •

    Supports three basic operations: • Append to a stream • Read all or part of a stream • Subscribe to a stream
  12. “But this is all really complicated and my juniors will

    never understand it all!” — Anonymous
  13. public abstract class LogRecord { public static readonly byte[] NoData

    = Empty.ByteArray; public readonly LogRecordType RecordType; public readonly byte Version; public readonly long LogPosition; public class PrepareLogRecord: LogRecord, IEquatable<PrepareLogRecord> { public const byte PrepareRecordVersion = 0; public readonly PrepareFlags Flags; public readonly long TransactionPosition; public readonly int TransactionOffset; public readonly int ExpectedVersion; public readonly string EventStreamId; public readonly Guid EventId; public readonly Guid CorrelationId; public readonly DateTime TimeStamp; public readonly string EventType; public readonly byte[] Data; public readonly byte[] Metadata;
  14. Index Entries • Hash of stream name • Event number

    • Logical position within storage
  15. P-Table (1m entries) P-Table (1m entries) P-Table (1m entries) Memtable

    (1m entries) P-Table (4m entries) P-Table (4m entries)
  16. HA • Fully consistent quorum-based replication • No shared storage

    requirements • Works best with an odd number of servers • Nodes use Paxos to elect a master
  17. Discovery • Nodes discover each other via DNS • One

    DNS entry points to each node • Nodes gossip amongst themselves • Client can discover nodes via DNS
  18. More Information • Event Store: http://geteventstore.com • Github: http://github.com/EventStore/EventStore •

    Twitter: @jen20, @GetEventStore • Docs: http://github.com/EventStore/EventStore/wiki
  19. If you liked this talk, I’m @jen20 on twitter. If

    you didn’t like this talk, I’m @stack72 on twitter.
  20. If you liked this talk, I’m @jen20 on Twitter. If

    you didn’t like this talk, I’m @sbellware on Twitter.
  21. Temporal Query • I as a doctor want to find

    patients for my clinical trial who: • Were diagnosed with condition Y inside the last 6 months • Had treatment A at least twice but no more than four times • Had an abnormal blood test where the white blood cell count was more than 10% lower than before treatment
  22. Temporal Query SELECT * FROM …. WHERE x IN (SELECT

    * FROM … WHERE y IN (SELECT * FROM … WHERE z IN (SELECT * FROM … WHERE λ…))))
  23. Query • I as someone who doesn’t live in San

    Francisco want to find users who said the word “starbucks” and the word “happy” in proximity to one another across any chat rooms they are in, so I know who not to ask for advice about coffee