The Entity Component System (ECS) is an architectural pattern that breaks a program into three kinds of things: entities, components and systems. It comes from video game development, where it represents the objects of a game world, but nothing in it is specific to games.

The pattern favours composition over inheritance. An entity is not defined by its place in a class hierarchy but by the components attached to it, and behaviour lives in systems that act on every entity carrying the components they ask for.

Key Concepts

Entity: a bare identity, usually nothing more than a unique integer ID. It holds no data and no behaviour of its own.

Component: a piece of plain data describing one aspect of an entity, such as Position, Velocity or Health. Components carry no logic.

System: a function that runs over every entity matching a component query. A movement system, for example, reads Velocity and writes Position on every entity that has both; entities lacking either are simply skipped.

Behaviour changes at runtime by adding or removing components. Give an entity a Velocity and the movement system starts moving it; take the component away and it stops, with no type change and no subclass.

Why It Works

Decoupling. Components are data buckets with no dependencies on each other, and systems only know the components they query. This removes the deep and wide inheritance trees that make object-oriented game code hard to extend.

Data-oriented performance. ECS is usually paired with data-oriented design: all instances of one component type are stored contiguously (structure of arrays), so a system walking them gets cache-friendly memory access.

Parallelism for free. A system declares which components it reads and which it writes. A scheduler can therefore run systems in parallel whenever their access sets do not conflict, with no locks written by hand.

Serialisable state. Because entities are IDs rather than pointers, the world can be saved, loaded or sent over a network without rebuilding references.

Storage Strategies

The two common layouts trade iteration speed against the cost of changing an entity’s shape.

Archetypes (tables). Every distinct set of components forms an archetype, a table with one column per component type. Iterating is fast because matching tables are dense, but adding or removing a component moves the entity to another table. Unity’s DOTS uses this layout.

Sparse sets. Each component type lives in its own sparse set indexed by entity ID. Adding and removing components is cheap, iteration over several component types is slower. Some engines let each component type choose: Bevy stores components in tables by default and moves one to a sparse set with #[component(storage = "SparseSet")].

Relation to Other Paradigms

ECS reads naturally as a functional pipeline: the world is a data store, and each system is a transformation over the subset of it selected by a query. Recent academic work formalises it that way, modelling entity creation, component changes and system runs as state transitions.

Systems usually communicate through shared component data. For rare, discrete events, polling flags every frame becomes wasteful, and implementations add an observer or event mechanism alongside the main loop.

The weak spot is the mirror of the strength: values travel between systems through components, so a bug can hide in a chain of systems that each look correct alone.

History

  • 1963: Ivan Sutherland’s Sketchpad stores drawing points apart from the shapes that reference them, an early form of the idea.
  • 1998: Thief: The Dark Project ships an engine built on an ECS, later reused for System Shock 2.
  • 2002: Scott Bilas of Gas Powered Games (Dungeon Siege) gives an influential GDC talk on component systems.
  • 2007: Adam Martin’s writing on the Operation Flashpoint: Dragon Rising work popularises the strict form: entities as IDs, components as raw data, all code in systems.
  • 2015: Apple ships an ECS in GameplayKit.
  • 2018: Unity shows its Megacity demo on the ECS-based DOTS stack.
  • 2020 onward: Bevy makes ECS the foundation of an entire Rust engine, including its renderer and UI.

References