# Routing

The **built-in routing system** allows clients to dynamically discover and communicate with subnet nodes capable of handling tasks (e.g., inference, validation, uploads).

### How It Works

See [how to use](/subnet-template/client/how-to-use.md) for an example on how to start a client node.

* The `Router` periodically **queries the DHT Records** for available nodes.
  * These nodes can be stored under **role-specific keys** (e.g., `"hoster"`), allowing the router to filter based on function.
* The router then keeps an **up-to-date list of reachable peers** that can be called for application-level RPC tasks.

### Customizing Node Discovery

To tailor this to your own subnet:

* Modify `get_node_infos(...)` to fetch nodes based on your custom UID (e.g., `"trainer"`, `"validator"`, `"relayer"`)
* Use metadata to prioritize nodes
* Extend the ping logic to measure latency, uptime, or region

### Periodical Routing Updates:

In this example from the Inference Example, each node that hosts the model is stored in the DHT Records using "hoster" as the key. The client can then utilize this list&#x20;

In this function, update the `get_node_infos` to gather every node that should be able to be called to perform the tasks of a subnet.

```python
def _update(self):
  """
  Perform an immediate and synchronous refresh, may take time
  """
  hoster_infos = get_node_infos(
    self.dht,
    uid="hoster",
    latest=True
  )
  
  with self.lock_changes:
      self.state.remote_servers_infos.update_(hoster_infos)
      all_servers = [server.peer_id for server in hoster_infos]
  
  self.ping_aggregator.ping(list(all_servers), wait_timeout=self.config.ping_timeout)
  
  self.ready.set()
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hypertensor.org/subnet-template/client/routing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
