# Add read/write relationships

Copy as Markdown[View as Markdown](/docs/development/guides/resources/data/add-read-write-relationships.md)

***

Data stores become more useful when EventCatalog knows which resources read from them and write to them.

Use `writesTo` when a resource stores, appends, or updates data in a data store. Use `readsFrom` when a resource reads, queries, or depends on data from a data store.

## How relationships work[​](#how-relationships-work "Direct link to How relationships work")

Read/write relationships are defined on the resource that uses the data store.

For example, if `OrdersService` writes to `OrdersDatabase` and reads from `ProductRedisCache`, add `writesTo` and `readsFrom` to the service frontmatter.

/services/OrdersService/index.mdx

```
---
id: OrdersService
name: Orders Service
version: 1.0.0

# Data stores this service writes to
writesTo:
  - id: OrdersDatabase

# Data stores this service reads from
readsFrom:
  - id: ProductRedisCache
    # optional version. If omitted, EventCatalog uses the latest version.
    version: 1.0.0
---
```

## Create the data stores[​](#create-the-data-stores "Direct link to Create the data stores")

The referenced data stores still need to exist in your catalog.

* containers

  <!-- -->

  /

  * OrdersDatabase
    <!-- -->
    /
    * index.mdx
  * ProductRedisCache
    <!-- -->
    /
    * index.mdx

* services
  <!-- -->
  /
  * OrdersService
    <!-- -->
    /
    * index.mdx

The `id` values in `readsFrom` and `writesTo` must match the `id` fields in the data store frontmatter.

/containers/OrdersDatabase/index.mdx

```
---
id: OrdersDatabase
name: Orders Database
version: 1.0.0
container_type: database
technology: PostgreSQL
---
```

/containers/ProductRedisCache/index.mdx

```
---
id: ProductRedisCache
name: Product Redis Cache
version: 1.0.0
container_type: cache
technology: Redis
---
```

## Version matching[​](#version-matching "Direct link to Version matching")

You can provide a specific version when linking to a data store.

```
readsFrom:
  - id: ProductRedisCache
    version: 1.0.0
```

If no version is provided, EventCatalog uses the latest version.

## Visualize the relationships[​](#visualize-the-relationships "Direct link to Visualize the relationships")

When a resource reads from or writes to a data store, EventCatalog can show that relationship in the visualiser and on resource pages.

![Service visualiser showing read and write relationships to data stores](/assets/images/visualiser-with-data-16a711072efee53b2480d1a2153aa450.png)

## Next steps[​](#next-steps "Direct link to Next steps")

You can use the same relationship pattern when connecting data stores to services and agents.

* [Add data stores to services](/docs/development/guides/resources/services/add-resources-to-services/add-data-stores-to-services.md)
* [Add data stores to agents](/docs/development/guides/resources/agents/add-data-stores-to-agents.md)
