Skip to main content

distributed-state-network

Distributed State Network (DSN) is a Python framework for distributed applications. Each node sends its state to the other nodes automatically. An application does not send a request for the data.

Basis

DSN is a helper for Language Pipes. It is the default technology for shared state in Language Pipes. Two research documents give the basis of the design.

The Maintenance of Duplicate Databases (Paul R. Johnson, Robert H. Thomas)

Original RFC

Language Pipes needs a distributed database. This document was the first to describe direct mail updates. DSN uses this method.

Epidemic algorithms in replicated databases (extended abstract)

Paper

DSN uses a simple form of the gossip protocol from this paper. Each node does a check of the health of its connections every 3 seconds. At each check, the node selects one peer at random and sends an update to that peer. The paper shows that this method gives the best ratio of complexity to benefit. Thus all the nodes become synchronized after a short time. DSN operates on a local network, where the loss of packets is not frequent.

Quick start

1. Create the first node

The most simple DSN network has one node. To create this node, do these steps:

  1. Import DSNodeServer and DSNodeConfig.
  2. Set bootstrap_nodes to an empty list. The first node in a network has no bootstrap node.
  3. Start the node with DSNodeServer.start().
  4. Write the data to the state of the node with update_data().
from distributed_state_network import DSNodeServer, DSNodeConfig


def alert(message: str) -> None:
    print(message)


# Start a node
node = DSNodeServer.start(
    DSNodeConfig.from_dict({
        "node_id": "my_first_node",
        "port": 8000,
        "bootstrap_nodes": []  # Empty for the first node
    }),
    alert
)

# Write some data
node.update_data("status", "online")
node.update_data("temperature", "72.5")

How it works

DSN makes a peer-to-peer network. Each node keeps its own state database.

Key concepts:

  • Each node owns its state. Only that node can change its state.
  • The node sends each change of its state to all the connected nodes automatically.
  • A node can read the state of each other node immediately.
  • The nodes can encrypt all communication with AES-128-CBC. Each message has a new random IV.

Example: a distributed temperature monitor

This example shows a network of temperature sensors. Each sensor writes its temperature to its own state. The monitor station reads the temperature from each sensor.

Do these steps on each Raspberry Pi that has a sensor:

sensor_node = DSNodeServer.start(
    DSNodeConfig.from_dict({
        "node_id": f"sensor_{location}",
        "port": 8000,
        "bootstrap_nodes": [{"address": "coordinator.local", "port": 8000}]
    }),
    alert
)

# Update the temperature every 60 seconds
while True:
    temp = read_temperature_sensor()
    sensor_node.update_data("temperature", str(temp))
    sensor_node.update_data("timestamp", str(time.time()))
    time.sleep(60)

Do this step on the monitor station:

for node_id in monitor.peers():
    if node_id.startswith("sensor_"):
        temp = monitor.read_data(node_id, "temperature")
        print(f"{node_id}: {temp}°F")

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

distributed_state_network-1.2.0.tar.gz (20.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

distributed_state_network-1.2.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file distributed_state_network-1.2.0.tar.gz.

File metadata

File hashes

Hashes for distributed_state_network-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4993e6053fed178a9ab9d8b575abe7c24cc2b0e6c01334201fd6d9981473f4a8
MD5 4aadb0d3e11401b03f1c79dd5e069f5b
BLAKE2b-256 f1863a961a02de6bcfa39e03627b2942f0ca984c41ec7883f53cb3db3d45800b

See more details on using hashes here.

Provenance

The following attestation bundles were made for distributed_state_network-1.2.0.tar.gz:

Publisher: publish-packages.yml on erinclemmer/language-pipes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file distributed_state_network-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for distributed_state_network-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c07e73dda614e0d75412ae18bce6104b54cb27ccc51c04e56e0280ced1c115d
MD5 25081aa7ad47762572afff272248add7
BLAKE2b-256 c88d0ab45d276167995f9d1b4f6f46054d5ef9ea76e8e3c54ecf050030f23d1e

See more details on using hashes here.

Provenance

The following attestation bundles were made for distributed_state_network-1.2.0-py3-none-any.whl:

Publisher: publish-packages.yml on erinclemmer/language-pipes

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 files

1.1.0

2 files

1.0.0

2 files

0.6.7

2 files

0.6.6

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.6

2 files

0.5.5

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page