Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mongodb Laravel Package

enqueue/mongodb

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The enqueue/mongodb package provides a MongoDB-based message broker for Laravel/PHP applications, enabling asynchronous task processing via Enqueue (a PHP message queue library). This is a good fit for:
    • Event-driven architectures (e.g., order processing, notifications, background jobs).
    • Microservices where MongoDB is already used as a primary database.
    • High-throughput workloads where Redis/RabbitMQ may not be feasible.
  • Laravel Integration: Laravel’s built-in queue system (via Illuminate\Queue) can leverage Enqueue as a drop-in transport, making this a viable alternative to database queues (database driver) or Redis.
  • Trade-offs:
    • No native Laravel support: Requires Enqueue as a middleware layer (adds complexity).
    • Schema flexibility: MongoDB’s document model may not enforce strict queue message schemas (unlike Redis or RabbitMQ).

Integration Feasibility

  • Enqueue as a Middleware: The package implements the Enqueue transport interface, meaning it can be plugged into Laravel’s queue system via Enqueue’s Laravel bridge (enqueue/laravel).
    • Example workflow:
      // config/queue.php
      'connections' => [
          'mongodb' => [
              'driver' => 'enqueue',
              'dsn' => 'mongodb://user:pass@localhost:27017',
              'queue' => 'default',
              'options' => [
                  'exchange' => ['name' => 'laravel_jobs', 'type' => 'direct'],
              ],
          ],
      ],
      
  • Job Serialization: Enqueue uses PHP’s serialize() by default, which may cause issues with:
    • Laravel’s job payloads (e.g., closures, resources).
    • Large payloads (MongoDB has a 16MB document limit).
    • Solution: Use enqueue/serialization-json or enqueue/serialization-php for better compatibility.

Technical Risk

Risk Area Assessment Mitigation Strategy
Stale/Unmaintained Last release in 2018, no recent activity. Evaluate fork/maintenance status; consider alternatives (e.g., php-amqplib).
MongoDB Schema No built-in schema validation for queue messages. Implement custom validation in job handlers or use MongoDB’s schema validation.
Performance MongoDB may not match Redis/RabbitMQ for low-latency use cases. Benchmark against existing queue drivers; optimize indexes on _id and delayed_at.
Laravel Compatibility Potential conflicts with Laravel’s queue retry logic. Test with enqueue/laravel bridge; monitor job failures.
Dependency Bloat Adds Enqueue as a dependency (~50MB+ with dependencies). Justify ROI vs. alternatives (e.g., Laravel’s database queue).

Key Questions

  1. Why MongoDB?
    • Is MongoDB already in use? If not, does it justify the operational overhead vs. Redis/RabbitMQ?
  2. Job Payload Size
    • Are jobs likely to exceed 16MB? If so, consider chunking or alternative storage.
  3. Maintenance Commitment
    • Is the team prepared to fork/maintain if issues arise (e.g., PHP 8.x compatibility)?
  4. Monitoring & Observability
    • How will queue metrics (e.g., depth, failures) be monitored? MongoDB lacks native queue visibility.
  5. Fallback Strategy
    • What’s the disaster recovery plan if MongoDB becomes unavailable?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Queue Drivers: Replace database, redis, or sync with mongodb via Enqueue.
    • Job Classes: Use Laravel’s ShouldQueue interface; Enqueue will handle serialization.
    • Workers: Deploy Enqueue’s PHP worker (enqueue:consume) alongside Laravel’s queue worker.
  • Tech Stack Compatibility:
    Component Compatibility Notes
    PHP 8.x Unverified (last release predates PHP 8). Requires testing.
    Laravel 9/10 Works via enqueue/laravel bridge, but may need adjustments for new queue APIs.
    MongoDB 6.x Assumes MongoDB 3.6+ (last release’s target). May need driver updates.
    Docker Easy to containerize; ensure MongoDB and worker share a network.

Migration Path

  1. Phase 1: Proof of Concept
    • Install enqueue/mongodb + enqueue/laravel.
    • Test with a non-critical queue (e.g., notifications).
    • Validate:
      • Job serialization/deserialization.
      • Worker consumption (enqueue:consume mongodb://dsn).
  2. Phase 2: Pilot Rollout
    • Migrate one queue type (e.g., emails).
    • Compare performance/metrics vs. current driver.
  3. Phase 3: Full Cutover
    • Update config/queue.php to use mongodb as default.
    • Monitor for job failures (log to MongoDB’s failed_jobs collection or Sentry).

Compatibility

  • Enqueue Bridge: enqueue/laravel provides Laravel-specific integrations (e.g., Queue::later() support).
  • Laravel Queue Extensions:
    • Retry Logic: Enqueue respects Laravel’s retry-after but may need custom logic for exponential backoff.
    • Failed Jobs: Uses MongoDB’s failed_jobs collection (similar to Laravel’s failed_jobs table).
  • Known Gaps:
    • No native support for queue priority (workaround: use MongoDB’s priority field).
    • Delayed jobs: Requires MongoDB’s delayed_at field (manual setup needed).

Sequencing

  1. Prerequisites:
    • MongoDB instance (3.6+) with proper indexing on queue, body, and delayed_at.
    • Enqueue installed (composer require enqueue/mongodb enqueue/laravel).
  2. Configuration:
    • Set up config/queue.php with MongoDB DSN.
    • Configure Enqueue’s exchange/queue bindings (e.g., laravel_jobs).
  3. Worker Setup:
    • Deploy Enqueue worker (e.g., via Supervisor):
      [program:laravel-queue-worker]
      command=php /path/to/artisan enqueue:consume mongodb://user:pass@mongo:27017/laravel_jobs
      
  4. Testing:
    • Dispatch a test job: php artisan queue:work --queue=mongodb.
    • Verify job processing in MongoDB’s laravel_jobs collection.

Operational Impact

Maintenance

  • Dependency Updates:
    • Critical Risk: Package is abandoned (last release 5 years ago). Plan for:
      • Forking if critical bugs arise.
      • Manual PHP/MongoDB version compatibility patches.
    • Mitigation: Monitor enqueue/enqueue (core library) for updates.
  • Schema Management:
    • MongoDB collections (laravel_jobs, failed_jobs) require manual schema awareness.
    • Tooling: Use MongoDB Atlas or mongock for schema migrations.
  • Logging:
    • Enqueue logs to stderr by default. Configure structured logging (e.g., Monolog) for observability.

Support

  • Troubleshooting:
    • Common Issues:
      • Serialization errors: Use enqueue/serialization-json.
      • Worker stalls: Check MongoDB connection health; monitor pending_jobs count.
      • Permission errors: Ensure MongoDB user has find, insert, update, delete on collections.
    • Debugging Tools:
      • enqueue:list (list queues).
      • enqueue:consume --verbose (debug worker).
  • Vendor Support:
    • None: Community-driven (Gitter channel). Budget for custom support if critical.

Scaling

  • Horizontal Scaling:
    • Workers: Scale by adding more Enqueue workers (stateless).
    • MongoDB: Requires sharding for high-throughput queues (e.g., >10K jobs/sec).
  • Performance Bottlenecks:
    • Write Heavy: MongoDB writes may lag under high load. Test with ab or k6.
    • Read Heavy: Index queue and priority fields for fast job retrieval.
  • **Alternatives
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor