Contentsquare gave notification events their own Kafka topic after real-time alerts outran the consumer, and built tooling to trace emails inside its provider
Contentsquare, 2023. Notification system (Notifications microservice and its channels).
Organisation
Contentsquare
Evidence
Reported from production
System
Notification system (Notifications microservice and its channels)
Contentsquare Engineering blog, published 2023-08-10
Architecture
Product microservices publish Kafka events to a Notifications topic. A consumer in the Notifications microservice picks them up, builds the message through a templating system and sends email through the cloud provider's SDK; for Slack and Microsoft Teams it produces further Kafka events that dedicated microservices consume and publish. Metadata about sent notifications is kept in an SQL database.
Produces an AlertNotification Kafka event when the alerting pipeline detects an incident. The article follows the Alerting module because it is the most complex use case the notification system currently has.
Near: will produce a Kafka event called AlertNotification | Section: Journey of a notification
Notifications topic
The Kafka topic that carries notification events from other microservices to the consumer; created after a single shared topic was outgrown.
Section: Notification Consumer | Near: we created a dedicated Kafka topic specifically
Notification Consumer
Captures the events on the Notifications topic and orchestrates processing and sending according to the customer's channel.
Section: Notification Consumer
Templating System
Handles styles, translations and injection of dynamic values. Email bodies are EJS templates; Slack and Teams messages are JSON structures for Block Kit and Adaptive Cards.
Section: Templating System
Mailer service
Builds the EJS template into the email body that is handed to the email provider.
Near: the consumer will use the Mailer service
Slack and Microsoft Teams microservices
Dedicated services that store each platform's configuration and publish the message to the selected channels, fed by Kafka events from the Notifications microservice.
Near: we have dedicated microservices that store the
SQL database
Stores metadata on sent notifications, such as when an email was opened, for monitoring and business intelligence. A cron job deletes it after 60 days.
Near: This data is stored for 60 days
Email observability tool
An internal tool that consumes the events the cloud provider's email service emits about each email, every minute, and logs and stores their metadata in an SQL database.
Section: Email observability tool
Figures, as the source states them
Figure
As stated
Note
Where
Email notifications sent
40,000 emails per week
Around; email channel only, while Alerting was in progressive roll-out
Near: we send out around 40,000 email notifications
Users with access to the Alerting module
5,000 users
Out of approximately 100K users; progressive roll-out
Near: accessible to 5K out of approximately 100K
Notifications one customer with 50 real-time alerts could trigger
600 notifications per hour
The authors' example from the beta, not a measured rate
Near: they could trigger 600 notifications every hour
Move notification events off the shared inter-service Kafka topic onto a dedicated topic
contentsquare-2023-notification-system#d1at corpus version 26a1b3a7e3dd
Chosen
The team created a Kafka topic used only for notification events. In the same round of measures they optimised how notifications are stored and gave them a retention period; the post also reports a slow Notification Center API call caused by a page without pagination.
Near: To address these issues, we implemented several | Near: The latency was due to the absence
What forced it
During the beta of real-time alerts the Alerting service produced more events than the Notifications service could consume. The system still generated an excessive number of notifications after a Snooze feature was added against false positives, and the monitoring tool raised multiple Kafka lag alerts because the service was not designed for that load.
Section: Overcoming Scalability challenges
Reasoning
The authors say the dedicated topic reduces the load on the main Kafka topic, which other services use to communicate, and makes processing more efficient.
Near: This approach effectively reduces the load on
What worked before
All inter-microservice communication went through a single Kafka topic. The authors say this had worked well until the beta of real-time alerts was launched.
Near: This had been working well before we
Reviewer's notes
The post does not say whether the lag on the shared topic delayed other services' messages; it reports the lag alerts and the consumer falling behind.
A customer did not receive an email the system recorded as delivered, because SPF alignment was not configured
contentsquare-2023-notification-system#f1at corpus version 26a1b3a7e3dd
How it failed
A customer reported not receiving a specific email although the notification system indicated it had been delivered successfully. After examining logs at each step of the notification journey, the team found the cause was that SPF (Sender Policy Framework) alignment had not been configured.
Near: We encountered a situation where a customer | Near: we found it was due to SPF
Why defences did not hold
Logging and tracing covered the notification journey inside the system, but the external email service was a black box with no full view of its inner workings, so the team could not tell at first whether the fault was its own, such as a template rendering failure, or the provider's. The authors call the investigation exceptionally difficult.
Section: Path to Observability
Impact
The source reports one customer not receiving one specific email; it gives no wider count.
Near: We encountered a situation where a customer
Fix
The team worked with the Security team to configure SPF. They then built a Kibana dashboard for logs and a Grafana dashboard for the cloud resources used by notifications, added other teams' Kafka dashboards to their monitoring routine, and developed an internal email observability tool.
Near: we collaborated with the Security team to | Near: we built a Kibana dashboard to monitor | Section: Email observability tool
Pull the email provider's per-email events every minute into logs and an SQL database
contentsquare-2023-notification-system#d2at corpus version 26a1b3a7e3dd
Chosen
The team built an internal tool that consumes the events the cloud provider's email service can be configured to collect for each email, every minute, then logs them and stores their metadata in an SQL database, so that both Kibana and the database can be queried when troubleshooting.
Section: Email observability tool
What forced it
Investigating the undelivered email was exceptionally difficult because the team could not fully see inside the external email service it relied on, and that led the team to invest significant effort in observability.
Section: Path to Observability
Reasoning
The events serve troubleshooting, for example finding missing or non-compliant variables behind a template rendering failure, and business intelligence, where events such as Open show how users interact with emails.
Publish to Slack and Microsoft Teams from separate microservices fed by Kafka events
contentsquare-2023-notification-system#d3at corpus version 26a1b3a7e3dd
Chosen
When a customer has selected Slack or Microsoft Teams, the Notifications microservice produces Kafka events, and dedicated microservices that hold each platform's configuration consume them and publish the message to the chosen channels.
Section: Sending notifications
Reasoning
Slack and Microsoft Teams publish a message to a channel by completely different logic, and the dedicated services exist to handle each platform's specific requirements. More broadly, the authors say microservices let each team be independent and own its business components.
Near: Slack and Microsoft Teams have completely different | Near: Microservices allow each team to be independent