Skip to main content
Version: 2.0

Microservices

Workflows can span multiple Laravel applications. One app defines workflows, another defines activities. Both share a database and queue, each running its own queue:work process.

Shared Database and Queue

Point both apps at the same database and Redis queue:

// config/database.php — add to both apps

'connections' => [
'shared' => [
'driver' => 'mysql',
'host' => env('SHARED_DB_HOST', '127.0.0.1'),
'port' => env('SHARED_DB_PORT', '3306'),
'database' => env('SHARED_DB_DATABASE', 'workflows'),
'username' => env('SHARED_DB_USERNAME', 'root'),
'password' => env('SHARED_DB_PASSWORD', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
],
],
// config/queue.php — add to both apps

'connections' => [
'shared' => [
'driver' => 'redis',
'connection' => env('SHARED_REDIS_QUEUE_CONNECTION', 'default'),
'queue' => env('SHARED_REDIS_QUEUE', 'default'),
'retry_after' => 90,
'block_for' => null,
'after_commit' => false,
],
],

Run migrations from one app only:

php artisan migrate

If the apps use a different database connection than default, see Database Connection for how to point the models at the shared connection.

Defining Workflows and Activities

Register type keys so the engine can route tasks by name:

// App A (workflow service) — config/workflows.php

'v2' => [
'types' => [
'workflows' => [
'order-processing' => App\Workflows\OrderWorkflow::class,
],
'activities' => [],
],
],
// App B (activity service) — config/workflows.php

'v2' => [
'types' => [
'workflows' => [],
'activities' => [
'charge-payment' => App\Activities\ChargePaymentActivity::class,
],
],
],

The workflow schedules the activity by type key:

// App A — app/Workflows/OrderWorkflow.php

use function Workflow\V2\activity;
use Workflow\V2\Workflow;

class OrderWorkflow extends Workflow
{
public ?string $connection = 'shared';
public ?string $queue = 'workflows';

public function handle(int $orderId): array
{
$charge = activity('charge-payment', $orderId);
return ['order' => $orderId, 'charge' => $charge];
}
}
// App B — app/Activities/ChargePaymentActivity.php

use Workflow\V2\Activity;

class ChargePaymentActivity extends Activity
{
public ?string $connection = 'shared';
public ?string $queue = 'activities';

public function handle(int $orderId): string
{
return "charged-{$orderId}";
}
}

Running Workers

Each app runs a queue worker on its own queue:

# App A
php artisan queue:work shared --queue=workflows

# App B
php artisan queue:work shared --queue=activities

App A's worker replays workflows and schedules activity tasks. App B's worker picks up those activity tasks, executes them, and returns results. The engine handles the handoff through the shared database.