[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Sharded PostgreSQL](../index.md) > Concepts > Resource relationships

# Resource relationships in Yandex Managed Service for Sharded PostgreSQL


Sharded PostgreSQL is a system for horizontal PostgreSQL scaling through sharding. Essentialy, these are multiple PostgreSQL clusters merged into a single Sharded PostgreSQL cluster.

A Managed Service for Sharded PostgreSQL cluster consists of _shards_, a _router_, and a _coordinator_. Routers and coordinators run on _hosts_, i.e., virtual machines with dedicated computing resources and reserved data storage.

## Shard {#shard}

A shard is a Managed Service for PostgreSQL cluster located in the same [folder](../../resource-manager/concepts/resources-hierarchy.md#folder) and [cloud network](../../vpc/concepts/network.md) as the Managed Service for Sharded PostgreSQL cluster.

There may be one or multiple shards. The maximum number of shards is unlimited and does not depend on the sharding type used in the cluster.

Each shard stores an independent data fragment. The data is distributed to shards based on a [sharding key](sharding-keys.md).

Queries are routed to a shard depending on the data it contains. A router is the entity that distributes queries among shards.

## Router {#router}

A router is the main component of a Managed Service for Sharded PostgreSQL cluster, responsible for routing queries.

A client connects to the router and sends queries over the PostgreSQL protocol. The router analyzes the query, redirects it to the shard that stores the relevant data, gets the query result, and returns it to the client.

The router uses sharding rules supplied by the coordinator to find the relevant shard.

When creating a cluster, you can choose between standard and advanced sharding. If you choose standard, the cluster will additionally get the `INFRA` hosts, which combine the router and coordinator roles. To ensure that such a cluster is fault-tolerant, we recommend creating at least three `INFRA` hosts in different availability zones. The maximum number of `INFRA` hosts is seven.

If you choose advanced sharding, dedicated `ROUTER` hosts will be provided for routers. The number of routers placed on such hosts is unlimited.

## Coordinator {#coordinator}

A coordinator is a component of a Managed Service for Sharded PostgreSQL cluster that stores sharding rules and balances loads on shards.

In standard sharding, the `INFRA` host acts as the coordinator. To ensure that such a cluster is fault-tolerant, we recommend creating at least three `INFRA` hosts in different availability zones. The maximum number of `INFRA` hosts is seven.

In advanced sharding, the `COORDINATOR` host acts as the coordinator. To ensure that such a cluster is fault-tolerant, we recommend creating three `COORDINATOR` hosts in different availability zones. The maximum number of `COORDINATOR` hosts is seven.

Coordinators store sharding rules in a QDB database running on `INFRA` or `COORDINATOR` hosts. This database represents an [etcd](https://etcd.io) cluster where the [consensus algorithm](https://raft.github.io) approves changes in data.

Using a coordinator, you can create or edit sharding rules for all routers at the same time. If you change the rules on one of the coordinators, the other coordinators and routers will get this update.


Be mindful of what is managed by the service and what, by the Yandex Cloud customer. Understanding these zones of control makes you an efficient user of cloud resources and helps avoid potential database-related issues. For more information, see [Zones of control between managed database (MDB) service users and Yandex Cloud](../../overview/concepts/mdb-responsibilities.md).