gosuperscript/zero-downtime-event-replays
Composer 安装命令:
composer require gosuperscript/zero-downtime-event-replays
包简介
Zero downtime event replay for Spatie's Laravel event sourcing package
README 文档
README
Usually you have to deal with a few problems that might cause downtime when replaying events. Your read models will be truncated at the beginning of a replay, and won't have the correct data until the replay has finished. Besides that, you'd have to wait with projecting newly recorded events until the replay has finished, to protect the replay order.
This package solves both problems, allowing a replay to happen to a copy of your read models. Once the replay is up to speed, newly recorded events will be played to both projections, so that your copy is kept up to date with the live read model. After verifying that the new replay is correct, the package enabled to promote your replay to live. Resulting in a (near) zero downtime release.
Usually running a new reply will look like this:
- Create a new replay, ang give it key to identify it. For example "add_extra_field_to_balance_projection". You also specify the projectors you want to play to in this step.
$manager = resolve(\Gosuperscript\ZeroDowntimeEventReplays\ReplayManager::class); // Create a replay $manager->createReplay('add_extra_field_to_balance_projection', [ "App\Projectors\BalanceProjector" ]);
- The replay can be started. When replaying, it calls the
useConnectionmethod on the projector. So the projector knows where it should write its data to. This package comes with an EloquentZeroDowntimeProjector that gives you some magic for dealing with different connections.
$manager->startReplay('add_extra_field_to_balance_projection');
- Once the replay is finished, but there is still some lag to production because of newly recorded events. You can start the replay again, it will start from the latest projected event. Its always possible to monitor the state of the replay and the lag compared to production.
// get the state & progress of your replay $manager->getReplay('add_extra_field_to_balance_projection'); // how many events is the replay behind the event stream? $manager->getReplayLag('add_extra_field_to_balance_projection');
- Once there is no lag, we can start projecting new events to replays.
$manager->startProjectingToReplay('add_extra_field_to_balance_projection');
- Once every thing checks out, you can promote your replay to production.
$manager->putReplayLive('add_extra_field_to_balance_projection');
- Lastly you can cleanup your replay
$manager->removeReplay('add_extra_field_to_balance_projection');
Installation
You can install the package via composer:
composer require gosuperscript/zero-downtime-event-replays
Usage
$manager = resolve(\Gosuperscript\ZeroDowntimeEventReplays\ReplayManager::class); // Create a replay $manager->createReplay('your_replay_key', ['projectorA', 'projectorB']); // Start replay history $manager->startReplay('your_replay_key'); // get the state & progress of your replay $manager->getReplay('your_replay_key'); // how many events is the replay behind the event stream? $manager->getReplayLag('your_replay_key'); // once a replay is up to date with the event stream, we can project events to it when they happen $manager->startProjectingToReplay('your_replay_key'); // Once the replay is approved, we can promote it to production $manager->putReplayLive('your_replay_key'); // Or we can delete the replay $manager->removeReplay('your_replay_key');
ZeroDowntime projectors
In order to make projectors work with zero downtime replays, they have to implement the ZeroDowntimeProjector interface. This interface asks you to implement the following methods:
interface ZeroDowntimeProjector { // This method lets the projector know that its replaying on a replay public function forReplay(): self; // Sets the connection to replay to, using the replay key. Each connection must be treated as a clone of the production schema. public function useConnection(string $connection): self; // Promote your connection to production public function promoteConnectionToProduction(): void; // cleanup/remove connection public function removeConnection(); }
Since most projections probably are replaying to eloquent, this package includes a EloquentZeroDowntimeProjector abstract class and a Projectable trait to be used on your eloquent read models.
To make your projectors work with this package:
- Make sure your projector extends the
EloquentZeroDowntimeProjector. - On all read models used by the projector, add the
Projectabletrait. - Implement a
modelsmethod on your projector, that returns all models that the projector writes to. This is used by the EloquentZeroDowntimeProjector in order to setup the right db scheme and promote the right models to production.
public function models(): array { return [ new BalanceProjector(), ]; }
- Everywhere where you query or update your read model, use the
forProjectionmethod.
// when truncating Balance::forProjection($this->connection)->truncate(); // when querying Balance::forProjection($this->connection)->where('user_id', $event->user_id)->first(); // when updating Balance::forProjection($this->connection)->where('user_id', $event->user_id)->increment('total', $event->amount); // when newing an instance $balance = Balance::newForProjection($this->connection, ['id' => $event->user_id, 'total' => $event->amount]); $balance->save();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
gosuperscript/zero-downtime-event-replays 适用场景与选型建议
gosuperscript/zero-downtime-event-replays 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 590.8k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「event-sourcing」 「gosuperscript」 「zero-downtime-event-replays」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 gosuperscript/zero-downtime-event-replays 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 gosuperscript/zero-downtime-event-replays 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 gosuperscript/zero-downtime-event-replays 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Immutable CQRS/ES library for Daikon-CQRS projects.
Use case driven EventSourcing - Let go of the Aggregate with the Dynamic Consistency Boundary (DCB) pattern.
Claude Code extension for PHP: audits (architecture, DDD, security, performance, PSR, design patterns, Docker, CI/CD, tests, docs), 3-level code review, automated bug fix, generators (DDD, CQRS, GoF patterns, PSR, tests, documentation, Docker, CI/CD), code explanation, refactoring. 26 commands, 62 a
Production-ready distributed tracing SDK for Laravel with event-sourced architecture, async HTTP transport, and cross-service context propagation
Daikon-CQRS bootstrap middleware with provisioning and tooling.
统计信息
- 总下载量: 590.8k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04