# Creating Server Groups with Affinity or Anti-Affinity Policy

Server groups can be used to control the affinity and anti-affinity scheduling policy for a group of servers.

An affinity policy for a server group denotes that all the virtual machine instances belonging to the server group would be hosted on a single hypervisor host.

You can configure a server group with an affinity policy and assign the server group to instances that host services that are closely tied together and frequently communicate with one another. When you have all such instances on the same hypervisor host, the communication between the instances is efficient.

An anti-affinity policy for a server group denotes that each virtual machine instance belonging to the server group would be hosted on a different hypervisor host.

You can assign a server group with an anti-affinity policy to virtual machine instances that run applications or services such as SQL server, and cannot afford to have a downtime. When the replicas of the such applications or services are placed on distinct hosts, the anti-affinity policy offers resiliency and the services suffer a negligible downtime.

An anti-affinity policy facilitates fault tolerance through redundancy, and helps in disaster recovery.

Refer to [OpenStack Server Group API reference](https://developer.openstack.org/api-ref/compute/#server-groups-os-server-groups) for information on OpenStack server group APIs.

## Configuring affinity and anti-affinity server groups in Platform9 Clarity UI

When you add a server group, you can assign an affinity or anti-affinity policy to it.

<figure><img src="/files/nDjbcafagTNpWa4E4Wzh" alt=""><figcaption></figcaption></figure>

Similarly, when you add an instance you can assign an affinity or anti-affinity server group to it.

<figure><img src="/files/RxIi2x99d2yJWkcdHw0D" alt=""><figcaption></figcaption></figure>


---

# 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.platform9.com/managed-openstack/5.8/instances/virtual-machines-anti-affinity.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.
