- How do I configure separate Elasticsearch clusters for reads and writes in Laravel using this adapter?
- Bind two `ElasticsearchAdapter` instances to Laravel’s service container—one for reads, one for writes—then inject the `ReadWriteAdapter` into your `Engine`. Use `.env` variables like `SEAL_READ_DSN` and `SEAL_WRITE_DSN` to dynamically configure DSNs per environment. Example: `$app->bind(ReadWriteAdapter::class, fn($app) => new ReadWriteAdapter($app->make('readAdapter'), $app->make('writeAdapter')));`.
- Can I use this adapter with Laravel Scout if I’m already using cmsig/seal as my Scout engine?
- Yes, but you’ll need to manually wrap Scout’s engine with the `ReadWriteAdapter`. Replace Scout’s default engine binding with your custom `Engine` instance using the adapter. Note: Scout’s built-in features (e.g., `searchable()`) may require adjustments to work with dual adapters. Test thoroughly in staging.
- What Laravel versions and PHP versions does this package support?
- The package requires PHP 8.1+ and is designed for Laravel 9+. Check the [cmsig/seal](https://github.com/PHP-CMSIG/search) repo for version compatibility, as this adapter depends on it. Always verify against your Laravel version’s minimum PHP requirements (e.g., Laravel 10 needs PHP 8.2+).
- How do I handle partial updates or race conditions when reads and writes are decoupled?
- Avoid partial updates entirely—always rewrite documents fully to prevent stale reads. For race conditions, implement optimistic concurrency control (e.g., versioning fields like `_version` in Elasticsearch) or use transactions if your write adapter supports them. The adapter’s `MultiAdapter` can help sync writes to both clusters atomically.
- Is there a performance impact if my read and write adapters are in different regions or data centers?
- Yes, latency will increase for cross-region calls. Mitigate this by: 1) Using connection pooling (e.g., Elasticsearch’s bulk requests), 2) Caching read-heavy queries in Redis with short TTLs, or 3) Deploying a local read replica. Monitor round-trip times with Laravel’s `queue:work` logging or APM tools like New Relic.
- Can I dynamically switch adapters based on tenant or environment (e.g., staging vs. production)?
- Yes, leverage Laravel’s service container to bind context-specific adapters. For example, use a `TenantAwareReadWriteAdapter` that resolves adapters from config per tenant ID. Override the binding in `AppServiceProvider::boot()` with environment-aware logic, like `config('services.seal.adapters.'.app()->environment()).`
- What alternatives exist for read-write separation in Laravel search without using this adapter?
- Consider Elasticsearch’s native [read replicas](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node-roles.html) or OpenSearch’s [multi-cluster support](https://opensearch.org/docs/latest/clusters/multi-cluster/). If using Laravel Scout, enable `scout:import` in queues for async reindexing. For simpler setups, Scout’s built-in caching (e.g., `scout:flush`) may suffice without dual adapters.
- How do I test this adapter in Laravel’s testing environment to ensure data consistency?
- Mock both adapters in tests using Laravel’s `Mockery` or `createMock()`. Verify writes propagate to reads by asserting search results after updates. Test edge cases like concurrent writes with `pestphp/pest` or PHPUnit’s parallel tests. Example: `$this->partialMock(ReadWriteAdapter::class, ['search'])->shouldReceive('search')->andReturn([]);`
- What’s the rollback plan if I encounter issues after deploying this adapter in production?
- Start by reverting to a single adapter in config (e.g., set `SEAL_READ_ADAPTER` and `SEAL_WRITE_ADAPTER` to the same DSN). Monitor for errors in Laravel’s `failed_jobs` table or Elasticsearch logs. If using queues, pause workers (`php artisan queue:pause`) and manually reprocess failed jobs. Always back up your search index before migration.
- How do I monitor for stale reads or failed writes in production?
- Instrument the adapter with Laravel’s `events` or a logging library like Monolog. Track metrics like `read_write_latency_ms` and `stale_read_ratio` (e.g., compare document timestamps between adapters). Use Laravel Horizon or StatsD to alert on anomalies. For Elasticsearch, enable slow query logging and set up alerts for high latency in Kibana.