# subject-too-long

A **subject** in the request, or of an event of a backup or of an import, is **longer than 1,024 characters**.

- **Routes:** `write-events`, `read-events`, `observe-events`, `read-subjects`, `restore-backup`, and `import-events`
- **Description:** `subject is too long: it may have at most 1024 characters`
- **Details:** **`value`**, the subject as the request, the backup, or the import gave it. When writing events, also **`event`** or **`precondition`**, the place of the event or the precondition in its list, counting from 0. When reading or observing events, also **`option`**, which is `fromLatestEvent` where the subject is the one of that option. When restoring a backup or importing events, also **`eventId`**, the ID of the event.

## Why It Happens

A **[subject](/docs/eventsourcingdb/subjects)** may have **at most 32 segments** and **at most 1,024 characters**, see **[Limits](/docs/eventsourcingdb/limits#size-limits)**. The database keeps a subject together with every subject above it, so the memory and the disk space that an event takes grow with the length and the depth of its subject at once, and the bounds keep that in proportion. A typical cause is a subject built from long values, such as names, titles, or serialized keys, rather than from identifiers.

The bounds hold for every subject that a request hands in: the subject of an event, the subject to read, observe, or list, the subject of `fromLatestEvent`, and the subject of a precondition. They hold for the subject of every event of a backup or of an import as well. When restoring a backup, the restore fails at the event, and the database removes what it has restored so far, see **[When a Restore Fails](/docs/eventsourcingdb/backup-and-restore#when-a-restore-fails)**. When importing events, the import fails at the event, and the database removes what it has imported so far, and keeps the schemas that were registered before it.

## How to Fix It

Build the subject from **short identifiers**, such as `/books/42` rather than the title of the book. Events that an earlier version stored with such a subject **stay readable**, through a subject above it, through `/`, or with **[EventQL](/docs/eventsourcingdb/eventql)**, but a backup that holds one **cannot be restored**, and an export that holds one cannot be imported until its subject is changed.

## Example

To read the events of a subject of 1,025 characters, EventSourcingDB answers with this error, as a line of the stream, and then ends the stream with its `end` item. The value is shortened here:

```json
{
  "type": "error",
  "data": {
    "code": "https://docs.eventsourcingdb.io/errors/subject-too-long",
    "description": "subject is too long: it may have at most 1024 characters",
    "details": {
      "value": "/books/aaaaaaaaaaaaaaaaaaaa…"
    }
  }
}
```
