ryan-mars / stochastic Goto Github PK
View Code? Open in Web Editor NEWTypeScript framework for building event-driven services. Easily go from Event Storming → Code.
License: MIT License
TypeScript framework for building event-driven services. Easily go from Event Storming → Code.
License: MIT License
Organisations don’t usually have consistent languages to describe their domain. Silos actively fragment knowledge into locally consistent bubbles, but end-to-end language consistency is usually a myth. The larger the organization, the more specialized jargons thrive around a specific function.
A Bounded Context is a unit of language consistency, a portion of the model that guarantees that every term has one and only one meaning, greatly improving our modeling precision.
A few clues about how to effectively partition a system:
- We’ll see where people tend to be, and usually different people tend to have different specific needs
- We’ll see boundaries, between different phases and swimlanes, often pointing to different needs.
Credit: Alberto Brandolini
Epic #4
Easily represent arbitrary code (e.g. npm module or REST API) as a "External System" with a simple pattern for registering Commands and Events. This is not to be confused with sending/receiving commands/events from other Bounded Contexts implemented with Stochastic.
Epic: Event storm visualization #3
Epic: Airline Example #13
Epic: Bounded Context #7
Epic: Event replay #9
Two identically named events in two different services which share events should not be confused at runtime based upon __typename
alone.
Epic: Shapes #36
Maybe later:
Aggregate
class for declaring Commands and Events that "operate on" the aggregate“The Aggregate”
I kept the name ‘aggregate’ mostly for historical reasons, EventStorming was born around Domain-Driven Design and Aggregates, so it makes little sense to look for another name. Aggregates are unit of transactional consistency within a software system. More interestingly they are little state machines that expose consistent behaviour.
— Alberto Brandolini
Illustration ©️ Avanscoperta
ReadModel (projections) and Policy are the only "event handler" components we have right now. It is conceivable that developers will want to respond to events in ways we have not yet conceived. It would be nice if there was a base class EventHandler
they could use or extend to suit their needs.
Epic: Bounded Context #7
Need a way to mark certain events as public and have the BoundedContext put those on the EventBridge bus.
Some folks will not want to use an aggregate. In that case commands should just generate events that are saved/emitted irrespective of a specific aggregate.
Simplify the specification of Event and event shapes as well as and runtime creation of events with data. Potentially use mixin pattern or superstruct's create
function.
Epic: Event #4
Epic: Airline Example #13
Epic: Shape #36
Epic: Command #8
Epic: AggregateRoot #11
Devs need docs
Some events will be emitted outside of the bounded context for others to react. We need a component that will aid the developer in describing this behavior.
// operations/src/service.ts
import { scheduling } from "scheduling/lib/index";
const SchedulingBoundedContext = new ExternalBoundedContext({
boundedContext: scheduling,
});
const {
ScheduledFlightAddedEvent,
FlightCreatedEvent,
} = SchedulingBoundedContext.events;
export const FlightManagementPolicy = new Policy(
{
__filename,
events: [ScheduledFlightAddedEvent, FlightCreatedEvent],
commands: [AddFlight],
},
async (event, commands) => {
// ...
}
);
export const operations = new EventStorm({
handler: "operations",
name: "Operations",
components: {
SchedulingBoundedContext,
FlightManagementPolicy,
AddFlight,
},
});
We need a way to discriminate events at runtime either with data, or when serializing/deserializing JSON.
Sam recommended __typename
.
Epic: Event #4
Epic: Airline Example #13
🤔 Since we know the set of domain events a command should produce we could use IAM policy conditions for fine grained (write) access control to the event store...
I'm sure there are many similar instances where we could follow "principle of least privilege".
Ideally you'd be able to produce this visualization from a CDK app using the stochastic module, that has not been synthesized or deployed. Perhaps at minimum we could require synthesis of the CDK app. Feedback requested.
Epic: Event replay #9
BoundedContext construct should publish the event schemas for public events (visible to other BoundedContexts) to the EventBridge schema registry.
Read Models
Read models are an interesting twist in modelling style: they provide the information needed in order to take a given decision.
... the design of Read Models is driven by the needs of a consequential decision.
Illustration ©️ Avanscoperta
Aggregate reducer produces current state from events.
Aggregate component should take a reducer function or some kind of monoid.
Epic: Aggregate #11
Wondering if there's a straight forward way that we could provide resource identifiers (ARN, table name, etc...) to any closure where the component is in scope. This could provide a useful escape hatch for developers doing weird stuff.
Imagine I had an edge case where I needed to interact with the database for a Read Model from within a command handler. Ignore all the reasons why this could be done with a proper Query, or whether we're violating CQRS. If each component provides getResourceLocator: () => Promise<string>
it could be used at runtime to fetch the ARN or other useful identifier for use with the AWS SDK (et.al.). If we stored these identifiers in SSM then the only runtime binding becomes a string key on the component uniquely identifying it.
const userNames = new ReadModel({
...
})
const createUser = new Command({
...
handler: async (command, aggregate) => {
const tableName = await userNames.getResourceLocator() // in this case we know it's a DynamoDB table
// ... do ugly stuff with the DynamoDB Client
}
})
Epic: Policy #10
Epic: Shapes #36
Epic: Event #4
Epic: Airline Example #13
source
and source_id
fields #35payload
boiler-plate in DomainEvent
#34Epic: Event replay #9
The following issues track discussion and implementation of key features of Stochastic for Event Storm -> Code.
Event #4
Policy #10
Command & Handler #8
Aggregate #11
Bounded Context #7
Read Model & Projection #6
Query a Read Model #5
External Service #2
AWS Serverless & CDK Infrastructure #12
Event replay #9
Event storm visualization #3
Pan Am Airline example app #13
event storm is decoupled from runtime architecture and infrastructure provider
fluent interface matching event storming output
Illustration ©️ Avanscoperta
The utility of stochastic would be best demonstrated through a useful example app. We'll resurrect Pan-Am airlines for this.
The story goes roughly like this:
Epic: Policy #10
Epic: Command & Handler #8
Epic: AggregateRoot #11
Aggregate Client should fetch the event history from the event store.
Epic: Aggregate #11
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.