Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation on Event Schema and Namespace guide #307

Merged
merged 1 commit into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ There are 2 CDK apps here:

As the opposite of stateful resources, stateless resources will have the ability to redeploy quickly without worrying
about any retainable data. For example, AWS lambdas and API Gateway have no retainable data when destroyed and spin up
easily. The [MicroService Applications](docs/developer/MICROSERVICE.md) resources will usually be here and they will
easily. The [Microservice Applications](docs/developer/MICROSERVICE.md) resources will usually be here and they will
have a lookup from stateful resources when needed.

You could access the CDK command for each app via `yarn cdk-stateless` or `yarn cdk-stateful`. The `cdk-*` is
Expand Down Expand Up @@ -85,25 +85,28 @@ You could list the CDK stacks with the `cdk ls` command to look at the stackId g
yarn cdk-stateless ls

OrcaBusStatelessPipeline
OrcaBusStatelessPipeline/BetaDeployment/MetadataManagerStack
OrcaBusStatelessPipeline/OrcaBusBeta/MetadataManagerStack
...
```

For example, deploying the metadata manager stateless resources directly from your computer as follows.

```sh
yarn cdk-stateless deploy OrcaBusStatelessPipeline/BetaDeployment/MetadataManager
yarn cdk-stateless synth -e OrcaBusStatelessPipeline/OrcaBusBeta/MetadataManagerStack
yarn cdk-stateless diff -e OrcaBusStatelessPipeline/OrcaBusBeta/MetadataManagerStack
yarn cdk-stateless deploy -e OrcaBusStatelessPipeline/OrcaBusBeta/MetadataManagerStack
```

NOTE: If you deployed manually and the pipeline starts running (e.g. a new commit at the source branch) your stack will be overridden to what you have in the main branch.
NOTE: If you deployed manually and the pipeline starts running (e.g. a new commit at the source branch) your stack will be overridden to what you have in the main branch. You are encouraged to look around `README.md` and `Makefile` of existing service stacks (both stateful/stateless) to adapt from existing setup.

## Development

_Heads up: Polyglot programming environment. We shorten some trivial steps into `Makefile` target. You may deduce step-by-step from `Makefile`, if any._

To develop your microservice application please read the [microservice guide](docs/developer/MICROSERVICE.md).

Do note that we have some shared resources that is expected to be used across microservices at [shared resource docs](./lib/workload/stateful/stacks/shared/README.md).
To develop your microservice application, please read:
- [microservice guide](docs/developer/MICROSERVICE.md)
- [event schema guide](docs/event-schemas/README.md)
- [shared resource guide](./lib/workload/stateful/stacks/shared/README.md)

### Typography

Expand Down
111 changes: 111 additions & 0 deletions docs/event-schemas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Event Schema

Login to AWS dev account: `AWS Console > Amazon EventBridge > Schema Registry > Schemas > orcabus.events`

## How to publish event schema into Registry?

1. Study existing schemas within this directory.
2. Follow the structure and, add your schema into this directory; including example event message instances.
3. Register your schema into [`config/stacks/schema.ts`](../../config/stacks/schema.ts).
- Follow the existing code structure.
- This is the only CDK TypeScript source file that need modifying.
- The [schema](../../lib/workload/stateless/stacks/schema/README.md) stack should detect changes and deploy upon successful build.
4. Make a PR with preferably only changes that contain about your event schema for clarity.

## Schema Registry

- When a service emits a message into the OrcaBus event bus:
- It has to follow the message format contract that published in [EventBridge Schema Registry](https://www.google.com/search?q=EventBridge+schema+registry).
- It must conform to event `source` property defined in `Namespace` section.
- A service may publish one or many event schemas into the registry as needed.
- Make event "observable". See [article](https://community.aws/content/2dhVUFPH16jZbhZfUB73aRVJ5uD/eventbridge-schema-registry-best-practices?lang=en).
- Event schema does not have to reflect 1-to-1 mapping with application backend database tables (i.e. how you store things). You may create "event transformer/mapper" layer within your code for this purpose.

### Schema Retention

- Multiple versions of the same schema is allowed.
- However, take note of [event schema evolution](https://www.google.com/search?q=event+schema+evolution).
- Introducing new `required` properties to the original schema may break downstream event subscriber.
- A service can emit multiple "editions" of the same message with varying event schema for backward compatibility.

Example:

```
/ MyDomainEntityStateChange (original schema)
service -- emits -- same message in two schema editions --|
\ MyNewDomainEntityStateChange (contain breaking changes)
```

```
service -- emits --> MyDomainEntityStateChange (no breaking changes, support additional properties)

(Multiple versions of `MyDomainEntityStateChange` schema represent as `Version 1`, `Version 2`, ..., inside EventBridge Schema Registry)
```

### Code Binding

- It is recommended to leverage [EventBridge Code Binding](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-schema-code-bindings.html) mechanism to auto-generate marshall/unmarshall ([serialisation](https://www.google.com/search?q=serialisation)) of the event schema; instead of manually parsing & validating the event message. Use of more advanced or, a better tooling fit-for-purpose is also encouraged when appropriate.
- The Slack [thread](https://umccr.slack.com/archives/C03ABJTSN7J/p1714731324414679) in `#orcabus` channel or https:/umccr/orcabus/issues/257 share DX tips for starter.
- Organise auto-generated code in trackable manner within your application source tree.

### Multiple Service Schemas

- Multiple services may publish the same or similar schema due to similarity of their domain modelling aspect.
- The event schema discriminator is the event `source` property of the event message instance.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps mention 'detail-type' here?
The source is only one dimension and a service can also emit different events types, i.e. multiple detail-types from the same source. Both together define the event schema.

- Subscriber routes the message of interest from upstream service event source through [EventBridge Event Rule](https://www.google.com/search?q=eventbridge+event+rule); within application deployment CDK code.
- When your application subscribe to similar schema from multiple sources, you should use their reverse domain (Namespace) to manage schema code binding purpose.

Example:

```
orcabus.bclconvertmanager@WorkflowRunStateChange
orcabus.workflowmanager@WorkflowRunStateChange
```

```
{
"detail-type": ["WorkflowRunStateChange"],
"source": ["orcabus.workflowmanager"],
"detail": {
"status": ["SUCCEEDED"]
}
}
```

```
{
"detail-type": ["WorkflowRunStateChange"],
"source": ["orcabus.bclconvertmanager"],
"detail": {
"status": ["SUCCEEDED"]
}
}
```

## Namespace

Service namespaces are for filtering Event Rule purpose. This is used in event `source` property when service emits messages. It denotes where the message is originating from. The convention follows reverse domain name. We follow "compat" format of [CDK stack directory name](../../lib/workload/stateless/stacks). i.e. Removing dash character from kebab-case.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, also use detail-type (see naming of examples)


```
orcabus.sequencerunmanager
orcabus.filemanager
orcabus.metadatamanager
orcabus.workflowmanager
orcabus.bclconvertmanager
orcabus.bclconvertinteropqcmanager
orcabus.bsshicav2fastqcopymanager
orcabus.cttsov2manager
orcabus.pieriandxmanager
```

Example:

```
orcabus.sequencerunmanager@SequenceRunStateChange
orcabus.filemanager@FileStateChange
orcabus.metadatamanager@LibraryStateChange
orcabus.workflowmanager@WorkflowRunStateChange
orcabus.bclconvertmanager@WorkflowRunStateChange
orcabus.bclconvertinteropqcmanager@WorkflowRunStateChange
orcabus.cttsov2manager@WorkflowRunStateChange
```