---
title: Data Types
slug: v4-4/tAWkWoXz6TuRtoc-1VFVI
docTags: 
createdAt: 2023-08-10T20:29:15.578Z
---

The conflict-free replicated data type (CRDT) data structure enables smooth peer‑to‑peer offline replication and online sync in distributed systems.&#x20;

When multiple offline Ditto stores make concurrent updates to the same CRDT object, the CRDT merge mechanism remediates the data collision so that, when sync takes place, they converge to a consistent state. For more information, see the *Platform Manual&#x20;*> [Sync and Replication Concepts](docId\:Vh2a6OTl4DLnEl0A-mIU8).

Following are the types of CRDTs you can use in Ditto:

:::hint{type="info"}
For an overview of documents, including fields and key-value pairs, see [Document Model](docId\:AmTy0OpHec33HDf-1IOhZ).&#x20;
:::

- [Register](docId\:eeXDc_d-t6lR3VgGcO7Qy)
- [Map](docId\:ltCtHSbI4y0U7RnsWneJG)
- [Counter](docId\:Y7L-8jGjrdwl-3AePgpv2)
- [Attachment](docId\:slQOBcNXTyF-KeLi7l8F8)

# Supported Types Overview

The following table provides a quick overview of the advanced data types you can use in Ditto, along with their guiding principles for conflict resolution, or *merge semantics*, a brief description, and a common usage scenario:

| **Type**     | **Merge Semantics**                                                                                | **Description**                                                                                                                                                   | **Use Case**                                                                  |
| ------------ | -------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `register`   | Last‑Write‑Wins Register, <br />Delta-state replication                                            | Stores a single value and allows for concurrent updates.                                                                                                          | Updates associated with later temporal timestamps *always* win.               |
| `map`        | Add-Wins Map,<br />Delta-state replication                                                         | Working in conjunction with the Register, stores the mapping of temporal timestamps to the values written in the Register to help resolve concurrency conflicts.  | Make a list of items in a document and update those items over time.          |
| `counter`    | Positive or Negative Counter,<br />The sum of all `Site_ID` Counters,<br />Delta-state replication | Converts a number value for a given key into a Counter. <br />Unlike a primitive `number`, value increments and decrements merge without conflict.                | Manage inventory and handle votes, such as stock details and survey results.  |
| `attachment` | Last-Write‑Wins Register,<br />Merges only when explicitly fetched                                 | Stores very large amounts of binary data, such as an image file, and allows for concurrent updates.                                                               | Reduce Small Peer resource usage by storing data outside of memory.           |
| `array`      | Last‑Write‑Wins Register,<br />Delta-state replication                                             | An extension of the `register` type,                                                                                                                              |                                                                               |



# Learning Resource: Interactive Tutorial

If you prefer learning by doing, see Jake Lazaroff's blog for a hands-on tutorial: "[An Interactive Intro to CRDTs](https://jakelazaroff.com/words/an-interactive-intro-to-crdts/)."&#x20;

# Update Behavior by Type

The following table provides an overview of the CRDTs and associated behavior for a given operation:

:::hint{type="info"}
For more information, see [CRUD Operations](docId:1CEXFnSWhjeqa_R6yyL-8).
:::

| **Operation**          | **Description**                                                                  |
| ---------------------- | -------------------------------------------------------------------------------- |
| `set register`         | Sets the value for a given field in the document.                                |
| `set map`              | Sets value for a given field in the `map`.                                       |
| `remove register`      | Removes a value for a given field in the document.                               |
| `remove map`           | Removes a value for a given key in the `map` structure.                          |
| `replace with counter` | Converts a `number` value for a given field into a `counter`.                    |
| `increment counter`    | Unlike a `number`, increments the `counter` by the given positive integer value. |
| `decrement counter`    | Unlike a `number`, decrements the `counter` by the given negative integer value. |

