# The Pub / Sub Paradigm - Overview

In other systems such as [WPILib command-based](https://docs.wpilib.org/en/stable/docs/software/commandbased/index.html) programming the implementor usually creates individual subsystem classes to represent their robot.  One might have a drivetrain subsystem, an elevator mechanism, vision, etc.  This works well for smaller, more controlled environments where design goals and constraints are very well known.  This model unfortunately begins to fall apart once you need to perform lots of communication between subsystems or integrate new APIs quickly.

The Topic / Subscriber (or pub / sub) system works a little differently.  The Pub/Sub paradigm defines Topics (similar to smaller, less complete subsystems) that can do nothing but send and receive messages each time their periodic method is called.  In Sunset these messages will take the form of python dictionaries. &#x20;

```python
message = {
    "x"    : 22377, 
    "y"    : 19376, 
    "theta": np.radians(8300)
}
```

{% hint style="success" %}
To take full advantage of the sunset logging capability, make sure all of your message types are serializable to JSON.
{% endhint %}

These messages will be sent to all of the subscribers of the sending topic once generated by the periodic method.  A copy of this message will then be stored in the messages dictionary of the subscriber for it to use in its own processing.&#x20;

{% hint style="info" %}
Topics themselves inherit the subscriber class.  This means that topics can receive data from other topics, this is very important and will be emphasized later.  As an end user you do not need to worry about execution order of Topic trees due to Sunset's DFS algorithm that orders execution leaves first, ensuring data is not stale.&#x20;
{% 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://docs.sunriserobotics.ai/the-pub-sub-paradigm-overview.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.
