Skip to content

Every subscriber is woken by every price #373

Closed

Description

@Miracle656

Background

const onPricePublished = (event: PricePublishedEvent) => {
  app.graphql.pubsub.publish({ topic: PRICE_TOPIC, payload: { priceUpdated: event } })
}

Every price goes onto one topic, PRICE_UPDATED, and each subscriber filters it
down with withFilter. Correct, and simple — but the filter runs per subscriber
per event. With a thousand subscribers each watching one pair, a single price
update runs a thousand filter callbacks, nine hundred and ninety-nine of which
discard it.

At the current scale this is invisible. It is also the kind of thing that is
cheap to fix now and a rewrite once there is traffic.

What to build

  • Publish to a topic keyed by pair and network, so the pubsub layer does the
    routing and a subscriber is only woken for its own pair.
  • Keep the current behaviour for a subscription with no network argument, which
    deliberately receives every network — the existing test covers this and must
    keep passing.
  • A metric of active subscriptions by pair, so the distribution is visible.
  • Measure before and after with a representative number of subscribers, and put
    the numbers in the PR. A performance change without a measurement is a guess.

Acceptance criteria

  • A subscriber is only woken for events matching its subscription
  • All five existing subscription tests still pass unchanged
  • A network-less subscription still receives every network
  • Active subscriptions are exported as a metric
  • The PR contains a before-and-after measurement

Drips Wave · Complexity: Intermediate · 150 points


Repo: Divinity-Labs/Lens. Node + TypeScript, Fastify, mercurius for
GraphQL at POST /graphql, Prisma on Postgres, Redis, Prometheus.

Run the tests: npm test. The tests are vitest, not jest. Running jest
here reports "66 suites, 0 tests" and means nothing. A single file is
npx vitest run src/__tests__/graphqlSubscription.test.ts.

Load test (prices) is already failing on main and has been for some
time. It is not your PR. Everything else should be green.

Read src/__tests__/graphqlSubscription.test.ts before you start. It is the
house pattern for testing this surface and it is good — it drives a real
subscription through a real server and asserts on what a client receives.

This service prices real assets on Stellar mainnet. A wrong number is worse
than a missing one, because the caller cannot tell.

Never elide an address, a contract id or a key in code, comments or test
fixtures. A previous batch shortened a contract id in an issue and five
contributors invented plausible-looking ids to fill the gap. Write it in full or
not at all.


Required: Before submitting, join the contributor Telegram so your work can be tracked and counted toward the Stellar Wave: https://t.me/+fxHXq8f1SwlkZDBk

Activity

  1. Muyideen-js commented on Oct 16, 2026

    @Muyideen-js

    @Muyideen-js has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    Hi, I can fix this

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @Muyideen-js to this issue.

  2. nonchalanttee22-lgtm commented on Oct 16, 2026

    @nonchalanttee22-lgtm
    Contributor

    @nonchalanttee22-lgtm has applied to work on this issue as part of the Stellar Wave Program's 10th wave.

    I'll step in and optimize the GraphQL price subscription pubsub routing for Lens (#373)! Routing price updates to pair-and-network-specific pubsub topics eliminates redundant subscriber wake-ups and CPU filter overhead.
    Execution Plan

    • Pair-and-Network PubSub Keying (src/api/graphql.ts):
      • Update onPricePublished to publish to dynamic topics keyed by pair and network (e.g., PRICE_UPDATED_${network}${assetA}${assetB}), while continuing to publish to a global PRICE_UPDATED topic when subscriptions omit the network argument.
    • Prometheus Metric:
      • Export active subscriptions as a Prometheus gauge (lens_active_subscriptions_total{pair="..."}).
    • Benchmarking & Testing (src/tests/graphqlSubscription.test.ts):
      • Verify all existing subscription tests pass, network-less subscriptions receive cross-network updates, and pair-scoped subscribers only wake for their exact target.
      • Include before-and-after benchmark measurements in the PR description.
        Assign this issue to me, and I'll submit a clean PR!

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @nonchalanttee22-lgtm to this issue.

  3. drips-wave commented on Oct 16, 2026

    @drips-wave

    Congratulations, @nonchalanttee22-lgtm! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on October 22, 2026.

    🧑‍💻 @nonchalanttee22-lgtm: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  4. drips-wave commented on Oct 25, 2026

    @drips-wave

    This issue has been completed by @nonchalanttee22-lgtm as part of the Stellar Wave Program's 10th Wave 🥳

    😎 @nonchalanttee22-lgtm: You earned 150 Points for completing this issue! Once the Wave's rewards are finalized, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions