Laravel

Laravel Distributed Systems

Queue-based communication, events, outbox pattern, idempotency, retries, circuit breaker, API contracts, versioning, saga basics

22 preguntas de entrevista·
Senior
1

What is the outbox pattern in Laravel distributed systems?

Respuesta

The outbox pattern stores messages/events in a database table during the same transaction as business data, then sends them asynchronously in a separate process. This ensures messages are always sent even if the system crashes after DB commit. Laravel's ShouldQueueAfterCommit is a partial implementation of this pattern, as it dispatches the job only after transaction commit, avoiding race conditions where the job executes before data is available.

2

What is the main difference between ShouldQueue and ShouldQueueAfterCommit?

Respuesta

ShouldQueue dispatches the job immediately to the queue, even if the DB transaction is not yet committed, which can cause race conditions. ShouldQueueAfterCommit waits for all DB transactions to be committed before dispatching the job, ensuring data is available when the job executes. Use ShouldQueueAfterCommit for jobs that depend on freshly created or modified data in a transaction, for example an email sending job after order creation.

3

What is idempotence in the context of Laravel distributed systems?

Respuesta

Idempotence means an operation can be executed multiple times without changing the result beyond the first execution. In Laravel, this prevents unwanted side effects during job retries or duplicate messages. For example, an idempotent order creation job checks if the order already exists before creating it, avoiding duplicates if the job is retried after a timeout. Use ShouldBeUnique, WithoutOverlapping or deduplicationId to ensure idempotence.

4

What is the main advantage of using events instead of direct job dispatch for inter-service communication?

5

In which context should ShouldBeEncrypted be used for queued jobs?

+19 preguntas de entrevista

Domina Laravel para tu próxima entrevista

Accede a todas las preguntas, flashcards, tests técnicos, ejercicios de code review y simuladores de entrevista.

Empieza gratis