# Key Based Deduplication

Key-based Deduplication is an efficient way to avoid duplicate entries when processing incoming Events alongside existing Incidents. It works by generating a Deduplication Key using a user-defined template specific to events from an Alert Source. This key helps identify and group duplicates.

## How it works

1. To use the key-based deduplication feature, the user must opt-in to a specific Service.
2. They can define a template to generate dedupe keys for each alert source within the Service. The user also specifies a duration (x) for the Deduplication Window.
3. For an incoming Event, the Deduplication Key is calculated based on the defined template.
4. This Key is then compared (using equality) against any previous Incidents within the Deduplication Window (last 5 minutes or the specified duration).
5. If an Incident with the same Deduplication Key is found, the current Event is deduplicated against that Incident.
6. However, if no matching incident is found, a new Incident is created.
7. Once the Deduplication Duration (x) elapses, the system recalculates the Deduplication Key using the defined template. This process continues for ongoing deduplication.

<figure><img src="https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2FeHd3HsC5hyhvEuLnEO2D%2FFlowchart%20for%20Dedup%20(1).png?alt=media&#x26;token=35737479-49df-459a-8c04-6295bc9b3aca" alt="Flow Diagram for Key Based Deduplication" width="563"><figcaption><p>Image. Flow Diagram for Key Based Deduplication</p></figcaption></figure>

## Prerequisites

The User Role associated with the user in the Team must have required permissions to manage Services (ability to manage Key Based Deduplication).

## Configure Key Based Deduplication

To add key-based deduplication:

1. Navigate to **Services** -> **Service Overview** -> select or search for your desired Service.
2. On the extreme right, expand the accordion -> In the Automation section, **View All.**
3. In the Key Based Deduplication section, **Add Dedup Key**.
4. Select an alert source to begin creating Deduplication Keys for your incoming Events.
5. On the right, you can view the *payload of the **latest** alert* for the chosen Alert Source.

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>: You can configure one Dedup Key per Alert Source.
{% endhint %}

6. The user needs to define a template to generate De-duplication Keys using the variables from the payload referenced on the right, for a particular alert source of a Service. For additional information on how to write templates, please refer to [<mark style="color:blue;">Go's standard library</mark>.](https://developer.hashicorp.com/nomad/tutorials/templates/go-template-syntax) \
   \
   A De-duplication key is calculated for the incoming event based on the template defined by the user.&#x20;

<details>

<summary><mark style="color:blue;">Here are some illustrative examples that demonstrate how to define a template for generating De-duplication keys</mark>.</summary>

![](https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2Fn5szHGagAWj5ecAjVegC%2FDedup%205.png?alt=media\&token=4872ec20-adc7-4e74-b5a3-b6ef080bf794)![](https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2FcYmMmhlk1ojZzpA8BHMg%2FDedup%204.png?alt=media\&token=8ee45da4-7a61-4ddd-9742-6659849cd69d)![](https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2FT4FZ1ZDUFXuClVxu5vjr%2FDedup%203.png?alt=media\&token=63de88ad-f927-4741-87b6-32a354133393)![](https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2FE7ldpwtnorA6exBo7aEg%2FDedup%202.png?alt=media\&token=c8ea8338-d0f3-4060-9853-1c6a14631b51)![](https://1574591692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F8TaWz01jmUJl58p4ZVel%2Fuploads%2FDab8j4N8PBRN5WIGWqzm%2FDedup%201.png?alt=media\&token=b8224807-557c-4219-8eee-84a59de5ab2b)

</details>

7. Define the **Deduplication Time,** in min(s) or hour(s).

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>: The maximum time limit is 48 hours.
{% endhint %}

8. Click **Save**.

## Delete Key Based Deduplication

To delete a key-based deduplication config:

1. Click on the **Key Based Dedup Rule** for a selected Service.
2. On the right-hand side, click **More Options** -> **Delete**
3. Click **Delete** again to confirm.

{% hint style="info" %} <mark style="color:blue;">**Note**</mark>: Kindly note that the deduplication will cease once the key is deleted.
{% endhint %}


---

# 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://support.squadcast.com/~/changes/idekPhcGN4Lv9B3e5j7p/services/alert-deduplication-rules/key-based-deduplication.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.
