For my next project I’m trying to find out if there has been any attempts already at creating a generic JSON domain event format. To compare, for REST APIs I am very happy to use JSON:API to structure any documents, as clients can understand what the parts are without necessarily understanding the domain specific parts. Similarly I would like to have a JSON domain event format, where an event consumer can be generic enough to understand what is going on structurally without necessarily understanding the domain specifics. This would allow event consumers to perform database projections, for example, without having to understand each individual domain event semantically.
As an example, here’s what I came up with myself as a starting point. Each event would be in DDD terms, so always works on entities, with aggregate information as metadata (type+id), and value objects as potentially complex JSON object attributes. JSON would look something like:
{
name: “CreatedComment”,
created: {type:“Comment”,id:“12345”},
attributes: {“title”:“Nice!”,“body”:“Great stuff!”},
addedRelationships:[
{name:“PostComments”,type:“Post”,id:“somepostid”}
]
}
Essentially a diff format, so focusing on what has changed, but with a domain event perspective. This way a generic event consumer would be able to project these in databases, especially schema-less versions like Neo4j or ElasticSearch, without having to necessarily understand any of the domain specific data.
Does anyone know of any such existing formats?
Thanks!