Scaling Mailcoach

On this page:

Rate limiting with Redis

When running multiple queue workers, the default cache-based rate limiter can cause race conditions where workers read the same counter simultaneously, exceeding your configured sending limit. This can lead to errors like Maximum sending rate exceeded from your email provider.

To solve this, you can enable Redis-based rate limiting, which uses atomic Redis operations that are safe for concurrent access across multiple workers.

Add the following to your .env file:

MAILCOACH_RATE_LIMIT_REDIS=true

Or set it directly in config/mailcoach.php:

'rate_limit_driver_is_redis' => env('MAILCOACH_RATE_LIMIT_REDIS', false),

We recommend enabling this if you’re running multiple queue workers and using Redis for your queue (which is the default Mailcoach setup with Horizon).

The rate limits themselves are configured per mailer in config/mail.php:

'mailers' => [
    'ses' => [
        // ...
        'mails_per_timespan' => 60,
        'timespan_in_seconds' => 1,
    ],
],

Cleanup

Some of Mailcoach’s tables can grow quite large when sending regular or large campaigns. You can configure cleanup (pruning) of data using the prune_after_days configuration array in config/mailcoach.php:

/**
 * Pruning settings determine after how many days the models should be pruned.
 * This will keep aggregated (calculated) statistics available, individual
 * subscriber rows will be deleted. Using null will disable pruning.
 * @since 8.13.0
 */
'prune_after_days' => [
    'sends' => null,
    'opens' => null,
    'clicks' => null,
    'unsubscribes' => null,
    'send_feedback_items' => null,
    'transactional_mail_log_items' => null,
],

We generally recommend deleting data older than 30 days, as you’d rarely need this data that long after sending. Aggregated (calculated) statistics will stay available in the summary views of campaigns, automation emails and transactional emails.

Make sure the php artisan mailcoach:prune command runs on a regular schedule in your application.

Campaigns