Hi GrowthBook team :wave:, We are currently using...
# ask-questions
s
Hi GrowthBook team 👋, We are currently using the JS SDK on the frontend like this:
Copy code
export const gbInstance = reactive(
  new GrowthBook({
    apiHost: "<https://cdn.growthbook.io>",
    clientKey: "sdk-xxx",
    ...
  })
)
But this generates a lot of CDN requests (We are in starter plan and just make the experiment online for 2 days, it becomes 12M requests 😢). To reduce requests, we’d like to add a backend cache layer. Our idea is to set up a custom backend endpoint like:
Copy code
export const gbInstance = reactive(
  new GrowthBook({
    apiHost: "<https://custom-backend-endpoint/growthbook>",
    clientKey: "sdk-xxx",
  })
)
And implement the backend API:
Copy code
GET <https://custom-backend-endpoint/growthbook/api/features/{sdk-key}>
This backend service would use the Ruby SDK to fetch feature settings from GrowthBook Cloud CDN, cache them, and then serve cached responses to the frontend.
Copy code
def index
  render json: { status: 200, features: growthbook_features_json(params[:sdk_key]), dateUpdated: Time.current.iso8601 }
end

private

def growthbook_features_json(sdk_key)
  Rails.cache.fetch("growthbook_features_#{sdk_key}", expires_in: 1.hour) do
    features_repository = ::Growthbook::FeatureRepository.new(
      endpoint: "<https://cdn.growthbook.io/api/features/#{sdk_key}>",
      decryption_key: nil,
    )

    features_repository.fetch || {}
  end
end
👉 Is this architecture supported / recommended? 👉 Would the JS SDK work properly if
apiHost
points to our custom backend instead of the GrowthBook CDN? Thanks!
f
Caching the payload works fine
many of the SDKs support real time updates
it is possible your caching may break this, but if you're okay with that
s
Thank you so much for the clarification!!! 🙏 For us, a short delay (e.g. up to an hour) is totally fine at this stage. We are still new to integrating GrowthBook, so as long as the solution works, that’s already great for us. We’ll start trying this approach. Really appreciate your help!
@fresh-football-47124 Sorry, one more quick question 🙏 In August we already used about 12M requests under the Starter plan. If we upgrade to the Pro plan now (still within August), how would the billing work? My assumption is: $20 base price + $10 × 10M overage = $120 total for August. Could you confirm if this understanding is correct? Thanks again!
f
I'm actually not sure
s
Got it, thanks a lot Graham! 🙏 I’ll discuss this with my boss and see which direction we want to take. Appreciate your quick help!