Skip to content

Improve Real-time response Handling for Remote Config #7044

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tusharkhandelwal8
Copy link
Contributor

This change prepares the Firebase SDK for future real-time quota enforcement, addressing potential user starvation. It ensures the SDK can fetch the latest template even when the real-time quota is exceeded.

We now include a retryInterval in the response when a connection hits a quota limit. This allows clients to get the latest template immediately and retry the connection after the specified interval. This approach guarantees users always have access to the latest data and can efficiently resume real-time services once their quota is restored.

Copy link
Contributor

Firebase AI Mock Responses Check ⚠️

A newer major version of the mock responses for Firebase AI unit tests is available. update_responses.sh should be updated to clone the latest version of the responses: v14.1

Copy link
Contributor

github-actions bot commented Jun 18, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @tusharkhandelwal8, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Firebase Remote Config SDK's real-time response handling, particularly for scenarios where a project exceeds its real-time quota. My changes introduce a mechanism to receive and apply a server-provided retryInterval, ensuring that clients can immediately fetch the latest configuration template and then efficiently manage their real-time connection attempts based on the recommended interval. This approach aims to prevent user starvation and proactively prepares the SDK for future quota enforcement.

Highlights

  • Quota Handling Improvement: The SDK now processes a retryIntervalSeconds field from real-time responses. This allows the server to dictate when a client should re-establish its connection after hitting a quota limit, ensuring a more graceful and efficient handling of quota exceedances.
  • Dynamic Backoff Management: A new method, updateBackoffMetadataWithRetryInterval, has been added to ConfigAutoFetch. This method calculates and persists a new backoff end time based on the received retryInterval, ensuring clients respect server-recommended delays before retrying real-time connections.
  • Shared Preferences Integration: The ConfigSharedPrefsClient is now passed to listenForNotifications and handleNotifications methods within ConfigAutoFetch. This enables the persistence of the dynamically calculated backoff end time, allowing the SDK to maintain state across sessions.
  • Persistence of Retry Interval: A new public method setRealtimeBackoffEndTime has been added to ConfigSharedPrefsClient to store the calculated backoff end time in shared preferences, ensuring the retry logic is consistently applied.
  • Enhanced Test Coverage: A new test case, realtime_updatesBackoffMetadataWithProvidedRetryInterval, has been added to FirebaseRemoteConfigTest. This test specifically verifies that the SDK correctly processes the retryIntervalSeconds from the server response and updates the backoff metadata accordingly.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces improvements to how the Firebase SDK handles real-time requests when a Firebase project has exceeded its available quota for real-time services. The SDK now respects a server-provided retry interval for real-time Remote Config connections. The changes are well-scoped, the logic is sound, and a new test case validates the core new functionality. No issues of medium, high, or critical severity were identified.

Copy link
Contributor

github-actions bot commented Jun 18, 2025

Test Results

 42 files   -  1 016   42 suites   - 1 016   1m 21s ⏱️ - 34m 31s
325 tests  -  5 660  325 ✅  -  5 638  0 💤  - 22  0 ❌ ±0 
662 runs   - 11 371  662 ✅  - 11 327  0 💤  - 44  0 ❌ ±0 

Results for commit c499e08. ± Comparison against base commit f08e0c7.

This pull request removes 5661 and adds 1 tests. Note that renamed tests count towards both.
com.google.android.datatransport.cct.CctBackendFactoryTest ‑ create_returnCCTBackend_WhenBackendNameIsCCT
com.google.android.datatransport.cct.CctDestinationTest ‑ cctDestination_shouldOnlySupportProtoAndJson
com.google.android.datatransport.cct.CctDestinationTest ‑ cctDestination_shouldSupportProtoAndJson
com.google.android.datatransport.cct.CctTransportBackendTest ‑ decorate_whenOffline_shouldProperlyPopulateNetworkInfo
com.google.android.datatransport.cct.CctTransportBackendTest ‑ decorate_whenOnline_shouldProperlyPopulateNetworkInfo
com.google.android.datatransport.cct.CctTransportBackendTest ‑ schedule_shouldAddCookieOnPseudonymousIds
com.google.android.datatransport.cct.CctTransportBackendTest ‑ schedule_shouldDropCookieOnMixedPseudonymousIds
com.google.android.datatransport.cct.CctTransportBackendTest ‑ send_CompressedResponseIsUncompressed
com.google.android.datatransport.cct.CctTransportBackendTest ‑ send_whenBackendRedirectsMoreThan5Times_shouldOnlyRedirect4Times
com.google.android.datatransport.cct.CctTransportBackendTest ‑ send_whenBackendRedirects_shouldCorrectlyFollowTheRedirectViaPost
…
com.google.firebase.remoteconfig.FirebaseRemoteConfigTest ‑ realtime_updatesBackoffMetadataWithProvidedRetryInterval

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 18, 2025

Startup Time Report 1

Note: Layout is sometimes suboptimal due to limited formatting support on GitHub. Please check this report on GCS.

Notes

Startup Times

  • fire-rc

    DeviceStatisticsDistributions
    oriole-32
    Percentilef08e0c73871386DiffSignificant (?)
    p10307 ±581 μs250 ±436 μs-56.8 μs (-18.5%)NO
    p25329 ±620 μs262 ±455 μs-66.8 μs (-20.3%)NO
    p50357 ±662 μs294 ±502 μs-63.1 μs (-17.7%)NO
    p75427 ±747 μs355 ±577 μs-72.3 μs (-16.9%)NO
    p90514 ±843 μs447 ±674 μs-67.1 μs (-13.1%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    3871386
    • 2025-06-18_10:00:47.228607_LcaK
    • 2025-06-18_10:00:47.231898_qIOH
    • 2025-06-18_10:00:47.231911_Ykop
    • 2025-06-18_10:00:47.231917_DrmT
    • 2025-06-18_10:00:47.231922_rxei
    • 2025-06-18_10:00:47.231926_QIJZ
    • 2025-06-18_10:00:47.231930_Xrbb
    • 2025-06-18_10:00:47.231934_Hgej
    • 2025-06-18_10:00:47.231938_FlAV
    • 2025-06-18_10:00:47.231941_wGNr
    redfin-30
    Percentilef08e0c73871386DiffSignificant (?)
    p10286 ±180 μs152 ±46 μs-134 μs (-46.9%)NO
    p25337 ±247 μs161 ±53 μs-176 μs (-52.3%)NO
    p50426 ±371 μs174 ±59 μs-252 μs (-59.2%)NO
    p75550 ±524 μs197 ±77 μs-353 μs (-64.2%)NO
    p90764 ±716 μs278 ±190 μs-487 μs (-63.7%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    3871386
    • 2025-06-18_10:00:47.228607_LcaK
    • 2025-06-18_10:00:47.231898_qIOH
    • 2025-06-18_10:00:47.231911_Ykop
    • 2025-06-18_10:00:47.231917_DrmT
    • 2025-06-18_10:00:47.231922_rxei
    • 2025-06-18_10:00:47.231926_QIJZ
    • 2025-06-18_10:00:47.231930_Xrbb
    • 2025-06-18_10:00:47.231934_Hgej
    • 2025-06-18_10:00:47.231938_FlAV
    • 2025-06-18_10:00:47.231941_wGNr
  • timeToInitialDisplay

    DeviceStatisticsDistributions
    oriole-32
    Percentilef08e0c73871386DiffSignificant (?)
    p10199 ±4 ms199 ±3 ms+513 μs (+0.3%)NO
    p25204 ±4 ms205 ±3 ms+1.20 ms (+0.6%)NO
    p50211 ±4 ms212 ±3 ms+1.23 ms (+0.6%)NO
    p75218 ±4 ms220 ±3 ms+2.09 ms (+1.0%)NO
    p90226 ±4 ms229 ±5 ms+2.76 ms (+1.2%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    3871386
    • 2025-06-18_10:00:47.228607_LcaK
    • 2025-06-18_10:00:47.231898_qIOH
    • 2025-06-18_10:00:47.231911_Ykop
    • 2025-06-18_10:00:47.231917_DrmT
    • 2025-06-18_10:00:47.231922_rxei
    • 2025-06-18_10:00:47.231926_QIJZ
    • 2025-06-18_10:00:47.231930_Xrbb
    • 2025-06-18_10:00:47.231934_Hgej
    • 2025-06-18_10:00:47.231938_FlAV
    • 2025-06-18_10:00:47.231941_wGNr
    redfin-30
    Percentilef08e0c73871386DiffSignificant (?)
    p10227 ±7 ms251 ±4 ms+24.1 ms (+10.6%)MAYBE
    p25234 ±8 ms258 ±4 ms+23.6 ms (+10.1%)NO
    p50243 ±11 ms268 ±4 ms+24.3 ms (+10.0%)NO
    p75253 ±14 ms280 ±4 ms+27.2 ms (+10.8%)NO
    p90264 ±19 ms300 ±9.6 ms+36.1 ms (+13.7%)NO

    20 test runs in comparison
    CommitTest Runs
    f08e0c7
    • 2025-06-17_14:04:00.219665_jVxl
    • 2025-06-17_14:04:00.219701_GrrJ
    • 2025-06-17_14:04:00.219713_tzRQ
    • 2025-06-17_14:04:00.219721_BWWY
    • 2025-06-17_14:04:00.219729_UsGW
    • 2025-06-17_14:04:00.219737_ejuQ
    • 2025-06-17_14:04:00.219743_LPho
    • 2025-06-17_14:04:00.219751_iHPe
    • 2025-06-17_14:04:00.219758_Mzxq
    • 2025-06-17_14:04:00.219765_dSnp
    3871386
    • 2025-06-18_10:00:47.228607_LcaK
    • 2025-06-18_10:00:47.231898_qIOH
    • 2025-06-18_10:00:47.231911_Ykop
    • 2025-06-18_10:00:47.231917_DrmT
    • 2025-06-18_10:00:47.231922_rxei
    • 2025-06-18_10:00:47.231926_QIJZ
    • 2025-06-18_10:00:47.231930_Xrbb
    • 2025-06-18_10:00:47.231934_Hgej
    • 2025-06-18_10:00:47.231938_FlAV
    • 2025-06-18_10:00:47.231941_wGNr

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/gjQNHkR771/index.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 18, 2025

Coverage Report 1

Affected Products

  • firebase-config

    Overall coverage changed from ? (f08e0c7) to 84.07% (3871386) by ?.

    34 individual files with coverage change

    FilenameBase (f08e0c7)Merge (3871386)Diff
    AutoValue_ConfigUpdate.java?29.41%?
    Code.java?0.00%?
    ConfigAutoFetch.java?87.70%?
    ConfigCacheClient.java?93.33%?
    ConfigContainer.java?94.29%?
    ConfigFetchHandler.java?92.94%?
    ConfigFetchHttpClient.java?86.27%?
    ConfigGetParameterHandler.java?96.45%?
    ConfigRealtimeHandler.java?41.38%?
    ConfigRealtimeHttpClient.java?73.57%?
    ConfigSharedPrefsClient.java?83.83%?
    ConfigStorageClient.java?100.00%?
    ConfigUpdate.java?100.00%?
    ConfigUpdateListener.java?0.00%?
    ConfigUpdateListenerRegistration.java?0.00%?
    CustomSignals.java?100.00%?
    DefaultsXmlParser.java?0.00%?
    FirebaseRemoteConfig.java?89.76%?
    FirebaseRemoteConfigClientException.java?75.00%?
    FirebaseRemoteConfigException.java?95.65%?
    FirebaseRemoteConfigFetchThrottledException.java?100.00%?
    FirebaseRemoteConfigInfo.java?0.00%?
    FirebaseRemoteConfigInfoImpl.java?100.00%?
    FirebaseRemoteConfigServerException.java?68.42%?
    FirebaseRemoteConfigSettings.java?61.54%?
    FirebaseRemoteConfigValue.java?0.00%?
    FirebaseRemoteConfigValueImpl.java?84.62%?
    Personalization.java?91.43%?
    RemoteConfig.kt?31.58%?
    RemoteConfigComponent.java?90.70%?
    RemoteConfigConstants.java?0.00%?
    RemoteConfigRegistrar.java?100.00%?
    RolloutsStateFactory.java?95.24%?
    RolloutsStateSubscriptionsHandler.java?100.00%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/UDXGmcq7mv.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jun 18, 2025

Size Report 1

Affected Products

  • firebase-config

    TypeBase (f08e0c7)Merge (3871386)Diff
    aar113 kB113 kB+605 B (+0.5%)
    apk (aggressive)212 kB212 kB+328 B (+0.2%)
    apk (release)4.59 MB4.59 MB+496 B (+0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/MrQcgq7epY.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants