Skip to content

[Blazor] Adds support for persisting and restoring disconnected circuits from storage #62259

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

Merged
merged 23 commits into from
Jun 11, 2025

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Jun 5, 2025

Details to be added. There are some missing things on this PR that will be done in separate PRs:

  • Gracefully persisting a circuit, including sending the state to the client.
  • Persisting a circuit to distributed storage, which will use HybridCache as a base implementation.

The detailed design can be found #60494

The main changes from the original design as well as some additional details are:

  • We rely on HybridCache for handling storage to distributed storage mechanisms.
    • This means we don't have to create individual packages for different distributed backends (redis, blob).
  • We provide a default implementation that leverages MemoryCache (same as disconnected circuits in CircuitRegistry) and that stores a limited number of persisted circuits but for a longer period of time (2h is the default).
    • We expect the amount of memory used to persist the circuit state to be in the range of dozens to hundreds of KB.
      • The way we persist state on disconnection is equivalent to the way we do so during prerendering and persisting more than 100Kb starts to degrade the experience. (You wouldn't push 10MB of state to a client on the first request).
    • Keeping state around for longer is cheaper than keeping the circuit for several reasons:
      • The circuit might continue to do work even if disconnected and consume resources like CPU and memory. The persisted state only consumes a fixed amount of memory that the developer is in control of.
      • The persisted state represents a subset of all the memory consumed by the application (we don't have to keep track of the individual components and so on).
    • We retain the persisted circuit state for 2h by default in memory or until we run out of capacity. The default is chosen as a trade-off between the average session duration and the % of circuits that we fail to resume because we discarded the state.
      • Apps need to adjust this to their individual needs based on their user's usage.

@github-actions github-actions bot added the area-blazor Includes: Blazor, Razor Components label Jun 5, 2025
@javiercn javiercn marked this pull request as ready for review June 6, 2025 09:35
@javiercn javiercn requested a review from a team as a code owner June 6, 2025 09:35
@javiercn javiercn force-pushed the javiercn/persistent-component-state-ungraceful branch from 7116e55 to 70da07d Compare June 6, 2025 15:38
Copy link
Member

@MackinnonBuck MackinnonBuck left a comment

Choose a reason for hiding this comment

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

Looks great so far - still need to do a deeper review of some parts.

@javiercn javiercn force-pushed the javiercn/persistent-component-state-ungraceful branch from 70da07d to 7820b1b Compare June 9, 2025 18:25
@javiercn javiercn force-pushed the javiercn/persistent-component-state-ungraceful branch from cf5a455 to aea83a7 Compare June 10, 2025 09:57
@javiercn javiercn requested review from pavelsavara and maraf June 11, 2025 10:55
Copy link
Member

@MackinnonBuck MackinnonBuck left a comment

Choose a reason for hiding this comment

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

Looks great!

@javiercn javiercn force-pushed the javiercn/persistent-component-state-ungraceful branch from aea83a7 to 8582da8 Compare June 11, 2025 13:46
@javiercn javiercn merged commit 2ee09f5 into main Jun 11, 2025
27 checks passed
@javiercn javiercn deleted the javiercn/persistent-component-state-ungraceful branch June 11, 2025 17:53
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview6 milestone Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants