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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

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
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.

1 participant