Home Projects Portfolio Dashboard Export PDF Log in

Scaling Communication: Building Idempotent Notification Workflows in Laravel

In the devlog-ist/landing project, managing user expectations through timely communication is vital. Recently, we overhauled our recommendation request system to ensure referees are kept in the loop without redundant messaging, moving from simple in-app alerts to a robust, multi-channel notification strategy.

The Challenge: Noise vs. Necessity

Our previous implementation relied on basic in-app notifications. If a user missed the Filament bell alert, they were effectively left in the dark regarding the status of their recommendation requests. Furthermore, as we introduced automated status tracking (like expiration warnings), we risked spamming users if our notification triggers weren't strictly idempotent.

The Implementation

We transitioned to a hybrid approach using Filament for in-app delivery and Laravel's notification system for email. To handle idempotency, we added nullable timestamp columns to our database schema. These columns act as gates, ensuring each notification is sent exactly once.

public function checkReferenceStatus(): void
{
    $requests = RecommendationRequest::whereNull('notified_expired_at')
        ->where('expires_at', '<', now())
        ->get();

    foreach ($requests as $request) {
        $request->user->notify(new ReferenceExpiredNotification($request));
        $request->update(['notified_expired_at' => now()]);
    }
}

This logic, triggered by a scheduled console command, checks for pending requests that have crossed their expiration threshold. By checking the notified_expired_at timestamp before firing the event, we guarantee that the user is only notified when the status transition first occurs.

Ensuring Consistency

Beyond simple notifications, we needed to make these interactions actionable. By routing notification links through a centralized controller, we can handle post-click lifecycle tasks—such as removing the notification row from the bell UI—immediately upon redirecting the user to their portfolio settings.

The Technical Takeaway

When building automated notification systems, guard your triggers with state markers. Use timestamp columns to track exactly when an event was processed; this simple pattern prevents duplicate messages and maintains clean, predictable user communication as your application scales.

Try this next:

Review your current notification triggers. If you are sending emails based on database state, ensure you have a dedicated 'notified_at' column for each event type to act as your idempotency key.


Generated with Gitvlg.com

Scaling Communication: Building Idempotent Notification Workflows in Laravel
Germanwithpants

Germanwithpants

Author

Share: