# Subscriptions: Getting Started
Subscriptions allow GraphQL clients to observe specific events and receive updates from the server when those events occur.
Much of the credit should be given to the Ruby implementation (opens new window) as they provided a great overview of how the backend should work.
Add the service provider to your
'providers' => [ \Nuwave\Lighthouse\Subscriptions\SubscriptionServiceProvider::class, ],
If you want to use the Pusher driver, you need to install the Pusher PHP Library (opens new window) for interacting with the Pusher HTTP API.
composer require pusher/pusher-php-server
If you want to use the Laravel Echo driver, you need to set the env
# Empty Response Optimization
Lighthouse returns the subscription channel as part of the response under
lighthouse.php is set to
API responses without a subscription channel will not contain
This optimizes performance by sending less data, but clients must anticipate this appropriately.
# Expiring Subscriptions
Subscriptions do not expire by themselves. Unless you delete a subscription, it will continue to broadcast events after the client has disconnected.
The easiest way to expire subscriptions automatically is to use the env
to set an expiration time in seconds (e.g.
LIGHTHOUSE_SUBSCRIPTION_STORAGE_TTL=3600 to expire in one hour).
# Pusher Expiration Webhook
If you are using the Pusher driver, you can use a
channel existence (opens new window) webhook to mitigate this problem.
When a Pusher channel is vacated (i.e. there are no subscribers), it will trigger the webhook,
which will instruct Lighthouse to delete the subscription.
The webhook URL will typically be:
You can add the webhook in the Pusher Dashboard. Select the type