01 / 03

What are subscriptions?

Difficulty: 6/10
real-time data, WebSocket transport, authorization

Subscriptions in GraphQL allow clients to receive real-time updates when certain events occur on the server. They are typically used for implementing features like live notifications, chat applications, or real-time data feeds. Subscriptions use WebSocket connections to push updates to clients as soon as relevant events occur.

Subscription fields are defined exactly as Query and Mutation fields are, but using the subscription root operation type instead:

Scenario Questions

0-2 years experience

  1. 1We have a simple chat component that should show new messages instantly. How would you add a GraphQL subscription to receive those messages?
  2. 2If a client subscribes to a stock price feed but the server never sends an update, what will the client see and how can you detect that situation?

2-5 years experience

  1. 1You added a subscription for order status updates, but after deploying, some users never receive the updates. Walk me through how you would debug the issue.
  2. 2When implementing subscriptions, we need to decide between using a dedicated WebSocket server or piggy‑backing on our existing HTTP server. What trade‑offs would you consider?

5-8 years experience

  1. 1Our platform must support thousands of concurrent subscription connections for live sports scores. How would you design the subscription layer to scale while keeping latency low?
  2. 2Explain how you would enforce per‑user authorization for a subscription that streams sensitive financial data, and what you would do if a token expires mid‑stream.

8+ years experience

  1. 1We are migrating from a legacy polling API to GraphQL subscriptions across multiple services. What architectural changes and cross‑team coordination would you plan to ensure a smooth transition?
  2. 2Describe a strategy for versioning subscription schemas in a large ecosystem where different clients depend on different fields, without breaking existing streams.

Follow-up Questions

  • How does the server know which events to push to which client?
  • What happens if the client loses its WebSocket connection?
  • Can you mix subscriptions with regular queries in the same request?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.