Knowledgebase update - Atom model
Tags: blockchain, java, javascript, kotlin
Published: 2019-05-13 08:25:13

---
title: Knowledgebase update - Atom model
published: true
description: 
tags: #blockchain #java #javascript #kotlin
---

# Introduction

[​Tempo](https://docs.radixdlt.com/alpha/learn/whitepapers/tempo) (the Radix consensus algorithm) provides one fundamental constraint: eventual consistency of state. To meaningfully build on top of this constraint, we need high-level, application-oriented constraints and structures. The Atom Model was designed to empower decentralised applications by enabling extensible implementations of financial systems (creating, minting, transferring and burning of tokens), data storage and transfer (messaging) and more.

# Specification

In distributed data storage, all participants must agree on a set of rules that govern how a state can be changed. As not every node can store all states, a state must be divided into smaller pieces of state that can be validated without requiring all other states. For this to work, state changes have to be explicit and need to support a mechanism that accepts or rejects a batch of state changes as a unit. In Radix, these state changes are Particles and this atomic batch of Particles is an Atom. The Atom Model describes its structure, rules and interface with Tempo.

# Hierarchy overview

The state of the ledger is the sum of small state changes. These individual state changes of the ledger are called Particles. To submit Particles (i.e. state changes) to the ledger, they must be placed inside an Atom.

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRqlQJtovHhhbm4Z6N%2F1.png?alt=media&token=ff47882d-1e1b-4236-b305-7ff2c93a60f2 "Atom")

Particles in later Atoms may update Particles that were stored as part of earlier Atoms (e.g. to store that certain tokens have been spent). The current state of the ledger is therefore composed of all the latest Particles (i.e. state changes), whose ordering relative to each other is ensured by Tempo.

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRqpzYhh7CcOM-_T2t%2F2.png?alt=media&token=39fcfa96-8c02-4d6a-a430-895109b17810 "Atom")

When many such state changes are to be submitted at once, it's hard to discern which belong together. This is troublesome for validation (i.e. accept / reject changes) as well as for end-users ("which Particles represent what?"). To provide a clear mechanism for Particle relationships, related Particles are grouped into Particle Groups.

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRqtjHGkrvoh8tTtrz%2F03.png?alt=media&token=4334770f-edec-4942-978d-ae66c05815e2 "Atom")

Note that any Particle must be submitted as part of a Particle Group, Particles can't go inside an Atom directly. This explicit grouping mechanism makes developing libraries, wallets and of course Radix node implementations simpler as managing relations between Particles is natively supported.

Atoms, Particle Groups and Particles are the core structural elements of the Atom Model. The following sections define them in detail.

# Particles

Particles are the core component that power the Atom Model, as they can be mixed and matched with other Particles in an Atom to form arbitrarily complex actions. There are many different types of Particles for different purposes which are [explained here](https://docs.radixdlt.com/alpha/learn/architecture/particle-types). Therefore, when talking about Particles it is important to differentiate between Particle types, which describe a type of Particle, and Particle instances, which describe instances of a certain Particle type. Particle instances form the state of the ledger, while particle types define the particle instance's state guarantees and rules.

![alt text] (https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRqwY2xMJSLRPpZVpT%2F04.png?alt=media&token=c231f44f-9344-481a-bac8-5ea8ba38164e "Atom")

Particle instances of different Particle types can be mixed within an Atom and within a Particle Group as permitted by the Particle type. What a Particle type can permit and disallow about the state of its instances is further explained in the article [Particle Types](https://docs.radixdlt.com/alpha/learn/architecture/particle-types).

# Particles are Finite State Machines

As established, Particle instances can be updated in later Atoms. Updating refers to changing the lifecycle state of a Particle to another state - e.g. from "non-existent" into "valid", or from "valid" to "invalid", or even from "valid" to "valid". Invalidation - marking Particle instances as invalid - is useful for all Particle types that can be consumed in a way (e.g. Tokens).

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRqzGP0v6F_kenU6a0%2F05.png?alt=media&token=97fbdf96-7a54-47c8-b5d8-5ee75584b96c "Atom")

Updating a Particle does not change its content, but its state. In fact, the content of a Particle being equal is used to identify that a later Particle with equal content is meant to be an update. "non-existent", "valid" and "invalid" are the three possible lifecycle states of any Particle instance, and the Particle type dictates which states are permitted in which order. That is, the finite number of lifecycle states a Particle instance can assume is controlled by the lifecycle finite state machine that the Particle type describes. With Particle lifecycle states in mind, consider an example of how Particles may be updated over time:

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRr1wK78hzdcBEt5FE%2F12.png?alt=media&token=81383e68-c31f-430c-91ac-0ab5308ede37 "Atom")

Note that each arrow marks a transition from one lifecycle state (in this example green, i.e. "valid") to another lifecycle state (in this example red, i.e. "invalid"). The transitions from non-existence into a valid existence have been omitted for clarity as they are implicit.

# Particle Groups

A Particle Group is a grouping of related particles with metadata in an Atom that represent one application-level action. An action could be issuing a transfer involving multiple particles, paying a fee, sending a message, or any logical action that a user or developer wishes to group.

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRr7ut_dJoeD7Elb9X%2F06.png?alt=media&token=c1a5522c-4590-46d7-b5dd-1d9b4a00ee08 "Atom")

# Metadata

Similar to Atoms, Particle Groups contain a string-based key-value store of metadata. This metadata is not validated or otherwise constrained in any way (besides size restrictions of an Atom) and can be freely used. Note that since all Particle Groups contain metadata and it does not influence other aspects of the Atom Model in any way, it will be omitted unless explicitly discussed for the rest of this article.

# Particle and Particle Group Indices

To uniquely identify Particle Groups within an Atom, they are indexed in the order they are added to their Atom. To uniquely identify a Particle within a Particle Group, Particles are indexed in the order they are added to their Particle Group. Note that both indices are zero-based.

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRrAAlGEXwELTtU_dP%2F07.png?alt=media&token=a5c00533-f7aa-4309-b7c1-a46ea9dbd06d "Atom")

Using the index of the Particle Group a Particle resides in, and the Particle's index within that group, a Particle can be easily referenced within an Atom following the [JSON pointer standard](https://tools.ietf.org/html/rfc6901) as follows:

>< atomId >/groups/< groupIndex >/particles/< particleIndex >

Note that 'atomId' is computed using the hash of the Atom. See [Formal Definition](https://docs.radixdlt.com/alpha/learn/architecture/atom-model#formal-definition) for further explanation. For example, the Particle identifier

>123/groups/1/particles/2

refers to the Particle with index 2 in the Particle Group with index 1, as illustrated here:

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRrD27zckP4zQdv6Wh%2F08.png?alt=media&token=e5133338-1da1-4bf5-8294-08ba638f638d "Atom")

This is helpful for debugging when an Atom is rejected by a node, since it can point to a specific Particle in a human-readable way.

# Dependencies within an Atom

It is often desirable to submit an atomic state change that is composed of multiple changes that are dependent on each other. Particle Groups in an atom can depend on the output of Particle Groups that come before it, ordered by index.

# Atoms

An Atom is an atomic container of state changes on the ledger. When an Atom is submitted to the network, either all its Particles (i.e. state changes) are accepted and stored or none are.

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeRpm19axT0gb1fsX3y%2F-LeRrFJZsim0aT92ab_L%2F09.png?alt=media&token=65d1e3fa-71a1-4efd-a99a-cea358ee0d56 "Atom")

Besides state changes in the form of Particles, grouped into particle Groups, an Atom also contains metadata, signatures and a temporal proof. Signatures are vital to ensure legitimacy of the state changes submitted in an Atom, while the temporal proof is crucial in achieving consensus on a common state of the ledger. Note that the temporal proof is not attached by the client but by the nodes. As signatures and temporal proofs are not relevant to the Atom Model directly, they will be omitted for the remainder of this article.

# Metadata

Atoms also contain a string-based key-value store of metadata. This metadata is not validated or otherwise constrained in any way (besides size restrictions of an Atom, see [Formal Definition](https://docs.radixdlt.com/alpha/learn/architecture/atom-model#formal-definition)) and can be freely used. Note that since all Atoms contain metadata and it does not influence other aspects of the Atom Model in any way, metadata will be omitted for the rest of this document.

# Atomicity

The atomicity of an Atom is useful for constructing complex actions where either all state changes are accepted or rejected a cohesive unit.

![alt text](https://blobscdn.gitbook.com/v0/b/gitbook-28427.appspot.com/o/assets%2F-LMPbV3hGbTEzGtYlH-m%2F-LeS7NIfC9Yl_P3V-Adn%2F-LeS7QMNMgMOOBn18sBP%2FScreenshot%202019-05-09%2012.05.51.png?alt=media&token=912578c3-4a6a-4131-9c90-1df17aa4fa73 "Atom")

An Atom is only accepted when none of its Particles are rejected, regardless of their position in the Atom.

# Formal Definition

# Formal Structure

The formal structural definitions of the Atom Model are a high-level overview. For the purpose of this definition, [item]+ shall denote that item must be included at least once, [item]* shall denote that item can be included an arbitrary number of times and item shall denote that item must be included exactly once.

# General Metadata
General metadata is arbitrary data about an item (e.g. Atom or Particle Group) in a string-based key-value store. The strings are UTF-8, their keys and values are arbitrary. The only restriction is size, which is indirectly imposed by the overall Atom size restriction. General metadata is defined as

>Key = <utf8>
Value = <utf8>
Metadata =
    [Key=Value]*

# Particle

The structure of Particles is defined in the [Particle document](https://docs.radixdlt.com/alpha/learn/architecture/particle-types). As Particles do not share any required structure, there is no common base structure.

# Particle Group

A Particle Group contains a non-empty indexed list of Particles with General metadata. A Particle Group's structure is

Formal Particle Group Structure

>Particle Group =
    General Metadata
    [Particle]+

# Atom

An Atom contains a non-empty indexed list of Particle Groups with Atom metadata. Atom metadata is similar to General metadata, except that it has special values that must be present and  have value constraints:

| Required metadata keys       | Purpose           | Value constraints  |
| ------------- |:-------------:| -----:|
| timestamp    | Timestamp when the Atom was submitted | positive integer
must be after Universe was created |

An Atom's structure is defined as

>Atom =
    Atom Metadata
    [Particle Group]+

# Atom Size Restrictions

The maximum number of bytes a compact serialised Atom may have is 65536.

# Formal Schema

The formal schema is a JSON schema that the JSON serialised version of an object must follow.

# Particle

The schema of Particles is defined in the Particle document. As Particles do not share any required structure, there is no common base schema.

# Particle Group

The formal JSON schema of a Particle Group is available here.

# Atom

The formal JSON schema of an Atom is available here.

# Implementation

The Atom Model is currently implemented in Java on the development branch of the Radix Core (the primary implementation of a Radix node) and the Radix Client libraries.

# Radix Core (Java)

The Radix Core implementation is currently only accessible to Radix Core developers.

# Client libraries

| Language       | Status           | Library  |
| ------------- |:-------------:| -----:|
| [Java](https://docs.radixdlt.com/alpha/develop/java-client-library-guide)      | Available  | [radixdlt-java](https://github.com/radixdlt/radixdlt-java) |
| [JavaScript](https://docs.radixdlt.com/alpha/develop/javascript-client-library-guide)      | Available       |   [radixdlt-js](https://github.com/radixdlt/radixdlt-js) |
| [Kotlin](https://docs.radixdlt.com/alpha/develop/kotlin-client-library-guide) | Available     |    [radixdlt-kotlin](https://github.com/radixdlt/radixdlt-kotlin) |
| Swift         | In development|radixdlt-swift|

# Join The Radix Community

[Telegram](https://t.me/radix_dlt) for general chat
[​Discord](https://discord.gg/7Q7HSZZ) for developers chat
[​Reddit](https://reddit.com/r/radix) for general discussion
[Forum](https://forum.radixdlt.com/) for technical discussion
​[Twitter](https://twitter.com/radixdlt) for announcements
[​Email](https://radixdlt.typeform.com/to/nyKvMV) newsletter for weekly updates
Mail to [hello@radixdlt.com](hello@radixdlt.com) for general enquiries