Sub topic 13
Modelling topics, frequency, and channel preferences
This chapter covers how to store what a subscriber wants to receive. It assumes you know basic SQL, can read Python and JSON, and have read the earlier chapters on the subscriber lifecycle, consent records, and the unsubscribe flow. The next chapter builds the preference centre screens on top of this model.
Why a preference model comes before the UI
A preference centre is only as good as the data behind it. If the data model cannot express "weekly digest only, no events, pause until January", the page can only offer a single unsubscribe button. Designing the model first gives you three benefits:
- The sending code can answer one question the same way every time: "may I send this message to this person?"
- Each choice a subscriber makes can be written to the consent audit trail.
- You can add a new topic or channel without rewriting the sending code.
Preferences narrow what you may send. They never widen it. A subscriber whose status is unsubscribed, or whose address is on the suppression list, receives nothing, whatever their topic settings say.
The three dimensions
Most lists need three kinds of preference.
| Dimension | Question it answers | Typical values |
|---|---|---|
| Topic | What do they want to hear about? | product updates, weekly digest, events |
| Frequency | How often at most? | immediately, daily, weekly, monthly |
| Channel | Where can we reach them? | email, SMS, push |
A fourth setting, a pause, is a time-limited reduction. It sits between "keep sending" and "unsubscribe", and it often saves a subscriber who is only overwhelmed for a while.
Topics
A topic is a category of message that a subscriber can accept or refuse on its own. Good topics follow how the subscriber thinks about your content, not how your team is organised. "Billing notices" is a topic a customer understands. "Lifecycle team campaigns" is not.
Keep the list short. Three to six topics is usually enough, and every extra topic makes the page harder to use. Each topic needs a stable key (weekly_digest), a display name, and a plain-language description. Never reuse a key for a different meaning, because old consent records refer to it.
Frequency
Frequency is a cap, not a schedule. "Weekly" means "no more than one marketing message per seven days". You still decide what to send. The cap protects subscribers from the case where several teams all send in the same week.
Channels
A channel is a delivery route. Consent for one channel does not carry over to another. Someone who agreed to email has not agreed to SMS. Store consent per channel and write a consent event each time it changes. This tutorial focuses on email, but the model below allows other channels to be added.
Transactional messages are outside preferences
Some messages are not marketing: password resets, receipts, security alerts, and the double opt-in confirmation itself. Preferences do not control these, and you should say so on the page. Keep this separation in the data model by giving every message type a category, either marketing or transactional. Only marketing messages pass through the preference check. Be strict about the boundary. Putting a promotion inside a receipt to get around a preference is a common cause of complaints and can breach the rules covered in the legal chapter.
A relational model
The JSON record from the spine is a good shape for an API response, but a database needs rows that you can query and index. Storing the preferences as one JSON blob makes questions like "who has opted in to events?" slow and awkward. The schema below uses one row per subscriber, topic, and channel.
CREATE TABLE topics (
key TEXT PRIMARY KEY,
display_name TEXT NOT NULL,
description TEXT NOT NULL,
active BOOLEAN NOT NULL DEFAULT TRUE
);
CREATE TABLE subscriber_topic_preferences (
subscriber_id BIGINT NOT NULL REFERENCES subscribers(id),
topic_key TEXT NOT NULL REFERENCES topics(key),
channel TEXT NOT NULL DEFAULT 'email'
CHECK (channel IN ('email', 'sms', 'push')),
enabled BOOLEAN NOT NULL,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now(),
PRIMARY KEY (subscriber_id, topic_key, channel)
);
CREATE TABLE subscriber_settings (
subscriber_id BIGINT PRIMARY KEY REFERENCES subscribers(id),
frequency TEXT NOT NULL DEFAULT 'weekly'
CHECK (frequency IN ('immediate', 'daily', 'weekly', 'monthly')),
paused_until DATE,
updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
CREATE INDEX idx_prefs_topic_enabled
ON subscriber_topic_preferences (topic_key, channel)
WHERE enabled;A few design choices are worth explaining.
- Explicit rows, not missing rows. A row with
enabled = FALSEmeans the subscriber said no. A missing row means they have not chosen yet. The two cases differ for consent. If you treat a missing row as "no", new topics start with nobody subscribed. If you treat it as "yes", you may send to people who never agreed. Pick one rule per topic and write it down. - Topics retire, they are not deleted. Setting
active = FALSEstops new sends while keeping old consent records valid. - Frequency and pause live in a separate table. They apply to the person, not to a topic, so putting them on every topic row would duplicate data and invite inconsistency.
- The partial index speeds up the common send query, which only needs enabled rows.
Default choices and consent
For double opt-in lists, the safest default is that a new subscriber receives only the topics they ticked on the sign-up form. Pre-ticked boxes are weak evidence of consent, and under GDPR a pre-ticked box does not count as valid consent. If you want a topic to start on, show it unticked and let the subscriber tick it.
Recording changes
Every preference change is a consent-relevant event. Reuse the consent_events table from the earlier chapter. The preferences_updated event type already exists, and the source column records where the change happened, for example preference_centre or one_click_header.
A change that affects several topics at once should write one event with a description of the change in consent_text. Storing the old and new values as JSON in that column is a simple way to keep it. Then you can answer a later question such as "what had this person chosen on 3 March?" by replaying events.
API shape
The API view can fold the three tables into the JSON structure from the spine. This keeps the front end simple and the database normalised.
{
"email": "[email protected]",
"topics": {
"product_updates": true,
"weekly_digest": true,
"events": false
},
"frequency": "weekly",
"paused_until": "2027-01-15"
}Applying preferences at send time
The model matters only if the sender enforces it. The function below decides whether one subscriber may receive one marketing message today. It is a sketch with the database calls left to you, and it shows the order of checks.
from datetime import date, datetime, timedelta, timezone
FREQUENCY_DAYS = {"immediate": 0, "daily": 1, "weekly": 7, "monthly": 30}
def may_send(subscriber, settings, topic_enabled, last_marketing_sent_at, suppressed, today=None):
"""Return (allowed, reason) for one marketing message.
subscriber: dict with a "status" key
settings: dict with "frequency" and "paused_until" (a date or None)
topic_enabled: True only if an explicit enabled row exists for this topic and channel
last_marketing_sent_at: timezone-aware datetime or None
suppressed: True if the address is on the suppression list
"""
today = today or date.today()
if suppressed:
return False, "suppressed"
if subscriber["status"] != "confirmed":
return False, "not_confirmed"
if not topic_enabled:
return False, "topic_off"
paused_until = settings.get("paused_until")
if paused_until and today < paused_until:
return False, "paused"
gap = timedelta(days=FREQUENCY_DAYS[settings["frequency"]])
if last_marketing_sent_at and datetime.now(timezone.utc) - last_marketing_sent_at < gap:
return False, "frequency_cap"
return True, "ok"
if __name__ == "__main__":
result = may_send(
{"status": "confirmed"},
{"frequency": "weekly", "paused_until": date(2027, 1, 15)},
topic_enabled=True,
last_marketing_sent_at=None,
suppressed=False,
today=date(2026, 12, 1),
)
print(result)Running it prints (False, 'paused'). The order is deliberate: the hard stops (suppression, status) come first, then the softer preferences. Returning a reason string makes the decision easy to log and test.
Common errors
- Treating the cap as a promise. A frequency cap limits how often you send. A subscriber who picks "monthly" expects at most one message per month. If a message is skipped because of the cap, decide whether to drop it or hold it for the next window. Holding many messages and then sending them all at once defeats the purpose.
- Checking preferences in the campaign tool only. If one system sends campaigns and another sends triggered messages, both must call the same check. Put the logic in one shared service.
- Time zones.
paused_untilis a date. Decide which time zone defines the end of that date, and keep to it. Store timestamps in UTC. - Unsubscribe and preferences drifting apart. Full unsubscribe sets
status = 'unsubscribed'and adds the address to the suppression list. It does not need to rewrite every topic row. Do not let a later preference save change the status back toconfirmed. Only a new confirmed sign-up should do that. - No audit trail. If preference changes are not logged, you cannot show later what a subscriber chose.
Summary of the model
| Concern | Where it lives | Rule |
|---|---|---|
| Overall permission | `subscribers.status` | Only `confirmed` may receive marketing |
| Hard stop | Suppression list | Always checked first |
| Topics and channels | `subscriber_topic_preferences` | Explicit rows, no assumed yes |
| Frequency and pause | `subscriber_settings` | Per person, not per topic |
| History | `consent_events` | One event per change, with source |
Exercise
A subscriber has status = 'confirmed', the events topic row is missing, and they have no pause. Your team decides to launch an events newsletter next week. Should this subscriber receive it, and what should the system do?
Show answer
No. A missing row means the subscriber has not chosen, so there is no consent for this new topic. The system should treat it as not enabled and exclude them from the send. To reach them, offer the topic in the preference centre or on a sign-up form, and when they tick it, write an enabled row and a preferences_updated consent event with the source.
Exercise
A subscriber unsubscribes through the one-click header, and later opens the preference centre from an old link and saves their topics. Which check prevents them from receiving email again, and why is it needed?
Show answer
The status check (and the suppression list check) stops it. The preference save may write topic rows, but sending still requires status = 'confirmed' and no suppression entry. Without this check, an old link could silently undo an unsubscribe, which breaks the subscriber's request and risks complaints. The save should also be rejected for non-confirmed subscribers.
Exercise
Why is frequency stored in subscriber_settings rather than as a column on subscriber_topic_preferences?
Show answer
Frequency applies to the person, as a cap on all marketing mail. Storing it on each topic row would repeat the value, allow different topics to disagree, and make updates more error-prone.