What is Metadata?
Metadata is a map of string keys to byte array values that you can attach to workflows at creation time. Unlike tags (which are for identification and retrieval), metadata is for storing contextual information.Metadata Use Cases
- Business context - Store customer info, order details, or request data
- Debugging information - Track request IDs, trace IDs, or correlation IDs
- Audit trails - Record who started the workflow and when
- Feature flags - Store configuration or feature toggle states
- Custom attributes - Any domain-specific data
Adding Metadata to Workflows
Attach metadata when creating a workflow:Storing Different Data Types
Since metadata values are byte arrays, you can store any serializable data:Strings
Numbers
JSON Objects
Serialized Objects
Metadata in CloudEvents
Metadata is included in CloudEvents emitted by Infinitic. When a workflow is dispatched, the metadata is available in theWORKFLOW_META field:
WorkflowMeta Class
Internally, metadata is managed by theWorkflowMeta class:
Combining Tags and Metadata
Use tags for workflow identification and metadata for context:Metadata Helper Functions
Create helper functions for common metadata patterns:Reading Metadata from Events
When listening to CloudEvents, you can extract metadata:Best Practices
Keep metadata lightweight
Keep metadata lightweight
Metadata is stored with the workflow. Keep it reasonably sized to avoid storage bloat.
Use consistent key naming
Use consistent key naming
Establish a convention for metadata keys (e.g., camelCase, snake_case) and stick to it.
Don't store secrets
Don't store secrets
Never store sensitive data like passwords or API keys in metadata.
Include trace IDs
Include trace IDs
Always include request/trace IDs for distributed tracing and debugging.
Document metadata schema
Document metadata schema
Maintain documentation of what metadata keys your application uses and their formats.
Use typed wrappers
Use typed wrappers
Create type-safe wrappers around metadata to prevent serialization errors.
Metadata vs Tags
| Feature | Tags | Metadata |
|---|---|---|
| Purpose | Identification & retrieval | Context & information |
| Format | Set of strings | Map of string to bytes |
| Queryable | Yes (getByTag) | No |
| Size limit | Reasonable (IDs/labels) | Flexible (but keep small) |
| Use case | Finding workflows | Storing context |
| Mutability | Immutable | Immutable |
Example: E-commerce Order Tracking
Related Topics
- Tags - Organize and query workflows
- CloudEvents - Access metadata in events
- Monitoring - Track workflows using metadata