---
title: Constraints
---

To keep integrity within typically an [event source](/chronicle/concepts/event-source/) when appending events to an [event sequence](/chronicle/concepts/event-sequence/),
you can leverage constraints. Constraints are rules that run on a database level within Chronicle, allowing or not allowing an event to be
appended. This is one of the main ways Chronicle enforces the [Dynamic Consistency Boundary](/chronicle/dynamic-consistency-boundary/chronicle/)
by validating that the decision remains correct at append time.

```mermaid
flowchart LR
    E["Append event"] --> C{"Constraint check<br/>at append time, in the database"}
    C -->|rule holds| OK["Appended to the<br/>event sequence"]
    C -->|rule violated| NO["Rejected<br/>constraint violation"]
```

## Unique Constraint

A **unique constraint** specifies events that work on a specific value you want to keep unique within an event source.
For instance, let's say you're creating a system for registering users, the username is typically something you want to keep a unique
constraint on. Any events that either create the user or modify the user name in any way would typically then be included in the
constraint definition.

## Unique Event Type Constraint

The **unique event type constraint** lets you constrain on a specific event type being unique per event source. If any attempt is made
to append the same event type twice for an event source, it will be a constraint violation.
