Event Store logo

sss https://eventstore.org Menu

Developer Blog

Applications and IEvent

  |   Written by: James Nugent   |   Articles

We had a question on Twitter about whether events stored in the Event Store have to implement any interfaces or inherit from a base class or similar. Fundamentally, the Event Store doesn’t care what you store inside it - you are responsible for serialization. The remainder of this post talks about the TCP Client API.

The reading methods on EventStoreConnection return an EventStreamSlice object, which contains an array of RecordedEvent objects (which are also used for the subscription callbacks). The important part of RecordedEvent looks like this:

public class RecordedEvent
{
    public readonly string EventStreamId;

    public readonly Guid EventId;
    public readonly int EventNumber;

    public readonly string EventType;

    public readonly byte[] Data;
    public readonly byte[] Metadata;
...

The writing methods take an enumerable of IEvent, which looks like the following:

public interface IEvent
{
    Guid EventId { get; }
    string Type { get; }
    bool IsJson { get; }

    byte[] Data { get; }
    byte[] Metadata { get; }
}

The Data field should contain a serialized version of the event. If you serialize as JSON and set IsJson to true, the internally hosted projections will be able to process the event.

Although it may be tempting to use the CLR Type Name in the Type field, it’s worth considering that projections use that type name in the when() construct, so it’s probably better to use a friendlier name there, and include the CLR type name as metadata or as part of the serialization.

If you’re using the Event Store for event sourcing, these details will likely be encapsulated by your repository.


Subscribe to the Event Store blog

Get the latest news and tutorials when they are released

You might also like

    Guest post: Subscription service for Event Store

      |   Written by: Steven Blair   |   Articles

    VME Retail have released version 1.0.0 of their Subscription Service, which is intended to make life that little bit easier for delivering events from Event Store to clients. The Subscription Service has been used privately by VME Retail Ltd for a few years in various solutions, and they have decided to open the code up to the rest of the Event Store community.

    Read article

    Case Study: How Event Sourcing is Spurring Linedata’s Digital Transformation

      |   Written by: Dave Remy   |   Articles

    Event sourcing is relatively new to the financial services industry. By implementing Event Store’s approach to support its digital transformation strategy, Linedata can be more responsive to the changing needs of its customers and gain a competitive edge in the market. “The core benefits of event-driven architecture allowed us to improve quality, performance and respond quickly to our customers,” said Adrian Tovey, who leads Linedata’s global program management. “Event Store has helped us meet the demand for change in the industry, a change in the way applications are used to deliver services to our customers; Linedata is at the forefront of those changes.”

    Read article

    Disabling disk caching in Ubuntu

      |   Written by: James Nugent   |   Articles

    Amongst the many interesting discussions I had at Build Stuff last week was about how it’s desirable to switch off disk caching for the disks used for Event Store databases to help ensure that data is durable in the face of power failures. This is actually true of many databases, indeed, postgres gives you a warning about the possible dire consequences of having write caching switched on when you may experience power failure. You can...

    Read article