It looks like I am having some issues with horizon...
# announcements
r
It looks like I am having some issues with horizontal scaling with the new SDK, I am migrating from webhooks to the new SDK. When I test locally everything seems to be working fine but when we deployed to one of our environments the features are not getting updated there, I can not tell why except that we have multiple BE instances. Does the SDK supports this?
f
BE?
b
i assume backend
r
Yes, exactly
b
which SDK are you using? if you have multiple backend instances, you'll likely need a caching layer like redis in front of it, since it's likely the features are being cached in-memory on the specific instance when they're updating. if you're using ruby, this example uses the rails cache (which has a redis strategy but this example is using memcache). there's also a GBFeaturesRepository for ruby, the example wasn't updated yet to use it though, but if you wanted to, in the rails cache block you can implement the
Growthbook::FeatureRepository#fetch
call. if you're using java, there's a method on the GBFeaturesRepository#onFeaturesRefresh that you can use to listen to updates to update your shared cache. in the javascript SDK, there doesn't seem to be a way to subscribe to feature updates but i'll check with the rest of the team to confirm.
r
We use javascript and I did look for a method exactly as you said and could not find
So far I am not removing the webhook implementation, that one is working for us just fine so far but I wanted to since it is deprecated. But until I am sure it will work for us as the webhooks did I can not do the migration
@better-magician-65629 could we try to follow up on this topic here again?
f
its very early for Tina, will take some time for her to respond.
r
no worries we can do this async, I just want to continue the conversation 🙂
b
since you're using the JS SDK, you may be able to take advantage of the SSE implementation for feature refreshing. you'll need the proxy for this on self-hosted – "_*Streaming* - Updates your application in real-time as features are changed or toggled in GrowthBook (Javascript and React only)_" (looks like our docs are out of date, java also supports SSE) .. all connected clients should get instant updates for feature refreshes. are you using SSE and experiencing issues? in the JS SDK there isn't currently a way to subscribe to feature updates with a callback.
we may not be auto-polyfilling yet, so in node.js you'll need to polyfill eventsource (docs) and use the autoRefresh option:
Copy code
await gb.loadFeatures({ autoRefresh: true });
r
I already had the autoRefresh as true
Copy code
constructor(
    @Inject(AB_TESTING_OPTIONS) private options: ABTestingOptions,
    private abTestingIntegrationService: ABTestingIntegrationService,
    private logger: LoggerService
  ) {
    logger.setContext(ABTestingService.name);

    setPolyfills({
      // Required for Node 17 or earlier
      fetch: fetch,
      EventSource: EventSource
    });

    this.growthbook = new GrowthBook({
      apiHost: '<https://cdn.growthbook.io>',
      clientKey: this.options.growthbookSdkKey,
      enableDevMode: true,
      trackingCallback: this.trackingCallback.bind(this)
    });
  }

  public async onApplicationBootstrap() {
    await this.growthbook.loadFeatures({
      autoRefresh: true,
      timeout: 2000
    });
  }
basically when one of our instances bootstraps it will load the features with autoRefresh: true, or at least it should
but when debugging I saw that not all of them were getting updated