# Performance and Scalability

To **keep consistency between replicates**, it's usually necessary to **guarantee that conflicting operations are done in the same order**.

Conflict-generating operations:

* **Read-write:** reading and writing concurrent operations.
* **Write-write:** two write operations.

Ensuring a global order in conflicting operations can be a time-consuming operation, which lowers the scalability potential.

* **Solution:** lower the consistency requirements so that the necessity for global synchronism can be avoided.

## Data-centric models

{% hint style="info" %}

### Consistency Model

A contract between a distributed data store and processes where the **data store specifies precisely which are the results for a concurrent read and write operation**.
{% endhint %}

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2FduDCkrOTZrqaHmhc8AHc%2Fa.png?alt=media&#x26;token=9eb9a7ae-79a8-4956-896a-eb912660fc9b" alt=""><figcaption></figcaption></figure>

### Continuous consistency

#### Degree of consistency:

* Replicates can differ in their **numeric value**.
* Replicates can differ in their **relative immutability**.
* There can be differences in the **number and order of update operations.**

#### **Conit**

Unity of consistency -> specifies the **unit of data** over which there **should be a consistency measure**.

#### Example: Conit

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2F5gikln93v26cwiNcOQ7x%2Fa.png?alt=media&#x26;token=ff0dbf4b-2356-4e72-8693-db2ac1ab8550" alt=""><figcaption></figcaption></figure>

Each replicate has a vector clock.

*B* sends to *A* the operation in grey.

* *A* permanently executed that operation.

Conit:

* *A* has 3 pendant operations:
  * Deviation of **order = 3**.
* *A* loses two of *B's* operations:
  * Max diff is *70 + 412 = (2, 482)*.
  * **Numerical** deviation of 482.

### Sequential consistency

The **result of any execution is the same if all operations of all processes are executed in the same sequential order**, and the operations of each individual process appear in the program's specified order.

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2FZ47t9g6bjOLlKkOGFShS%2Fa.png?alt=media&#x26;token=2eda054c-1040-45b3-bddf-98f271de9345" alt=""><figcaption><p>Consistent sequencial storage</p></figcaption></figure>

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2F9yYGUqQhVlJrn4JEFfUR%2Fa.png?alt=media&#x26;token=e1b5ae35-17d9-458a-9809-d0cffa320b89" alt=""><figcaption><p>Non-consistent sequencial storage</p></figcaption></figure>

### Causal Consistency

**Writes** that are related casuistically **have to be seen by all processes in the same order**. Concurrent writes can be seen in different orders by different processes.

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2FpT0LCk1PIiMzxawn9iA9%2Fa.png?alt=media&#x26;token=5a46934e-66f3-462f-884f-b916af688c0c" alt=""><figcaption><p>Violation of casuistic storage</p></figcaption></figure>

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2Fun4OdcU7rJww1GNWfmvg%2Fa.png?alt=media&#x26;token=1b23363d-f277-4b4f-b867-a3631cb39dcf" alt=""><figcaption></figcaption></figure>

## Operation grouping

### Definition

* Accesses to **locks** are consistent sequentially.
* Accesses to locks are **not permitted** **before** all the **previous writes** have been **completed.**
* Access to the data is **not allowed** **until** all previous **accesses** to **locks** have been **completed**.

### Base idea

It does not matter if the reads and writes of a **set of operations** are immediately known to all other processes. Only the **effect** of the set **needs** to be known.

<figure><img src="https://2387753953-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9sVneYw7epWOEEPKsfCf%2Fuploads%2FOP4mO1BAJ8DBwFIy2vmp%2Fa.png?alt=media&#x26;token=c7061bad-bd67-4f04-a42c-d1e649ab244c" alt=""><figcaption></figcaption></figure>
