Skip to content

Replace Valkey with DragonFly as session store and caching solution#43

Merged
zribktad merged 4 commits intomainfrom
feature/dragonfly
Mar 16, 2026
Merged

Replace Valkey with DragonFly as session store and caching solution#43
zribktad merged 4 commits intomainfrom
feature/dragonfly

Conversation

@zribktad
Copy link
Copy Markdown
Owner

Transition from Valkey to DragonFly for session management and caching, updating configurations, documentation, and integration tests accordingly. Implement DragonFly-specific options and health checks, and configure Docker and Kubernetes deployments for DragonFly.

…solution

- Updated docker-compose files to replace Valkey services with DragonFly services (master, replica, and proxy).
- Modified health checks and connection strings to use DragonFly.
- Updated documentation to reflect the changes from Valkey to DragonFly, including caching and session management.
- Implemented DragonFlyTicketStore for ASP.NET Core authentication ticket storage.
- Added DragonflyOptions for configuration settings related to DragonFly.
- Updated integration tests to remove Valkey references and use DragonFly.
- Configured HAProxy for DragonFly in Docker Compose and added Kubernetes deployment instructions for DragonFly.
Copilot AI review requested due to automatic review settings March 16, 2026 20:38
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 transitions the application's in-memory data store from Valkey to DragonFly. This change impacts session management, output caching, and data protection, aiming to leverage DragonFly's performance benefits and robust high-availability features. The update involves comprehensive configuration adjustments across development and production environments, alongside detailed documentation to support the new infrastructure.

Highlights

  • Migration to DragonFly: The primary change involves replacing Valkey with DragonFly as the in-memory data store for session management, output caching, and DataProtection key storage.
  • Configuration Updates: All relevant configuration files, including VS Code launch/tasks, appsettings.Development.json, and Docker Compose files, have been updated to reflect the change from Valkey to DragonFly connection strings and service names.
  • High Availability Setup: Production Docker Compose now includes a DragonFly master/replica setup with HAProxy for high availability, and new documentation outlines Kubernetes deployment using the DragonFly operator for automated failover.
  • Documentation and Code Refinements: Extensive updates were made to documentation (README, AUTHENTICATION, CACHING, OBSERVABILITY, TESTING) to reflect the new DragonFly integration, including details on its architecture, configuration, and benefits. Code-level changes include renaming ValkeyTicketStore to DragonflyTicketStore and introducing DragonflyOptions for connection settings.
Changelog
  • .vscode/launch.json
    • Updated Valkey__ConnectionString to Dragonfly__ConnectionString in all launch configurations.
  • .vscode/tasks.json
    • Replaced 'valkey' with 'dragonfly' in various Docker Compose tasks for starting, stopping, and managing services.
  • README.md
    • Updated references from Valkey to DragonFly for caching, authentication, and health checks.
    • Modified the Docker Compose quick start guide to include DragonFly services.
    • Updated the technology stack description to reflect DragonFly 1.27 as the cache/rate limit backing store.
  • docker-compose.production.yml
    • Replaced the single 'valkey' service with 'dragonfly-master', 'dragonfly-replica', and 'dragonfly-proxy' for a high-availability setup.
    • Configured DragonFly services with specific commands for memory limits and proactor threads, and added health checks.
    • Updated the API service's Dragonfly__ConnectionString to point to dragonfly-proxy with password support.
    • Adjusted service dependencies and volume names to align with the new DragonFly services.
  • docker-compose.yml
    • Replaced the 'valkey' service with a single 'dragonfly' service for development.
    • Updated the Dragonfly__ConnectionString for the API service to point to the new 'dragonfly' service.
    • Modified service dependencies and volume names to use 'dragonfly'.
  • docs/AUTHENTICATION.md
    • Updated diagrams and descriptions to refer to DragonFly as the session store and for DataProtection keys.
    • Changed mentions of 'ValkeyTicketStore' to 'DragonflyTicketStore'.
  • docs/CACHING.md
    • Rewrote the overview to introduce DragonFly, highlighting its master/replica topology and Kubernetes operator support.
    • Added new architecture diagrams for Single Instance, Multi-Instance (Docker Compose HA), and Kubernetes (Operator-managed HA) setups.
    • Updated configuration sections to use Dragonfly:ConnectionString and introduced ConnectTimeoutMs and SyncTimeoutMs options.
    • Modified explanations of cache key prefixes and caching/invalidation mechanisms to reference DragonFly.
    • Updated the infrastructure section for Docker Compose to detail the HA setup and added a new section for Kubernetes deployment.
    • Included a new section comparing DragonFly to Redis and Valkey, outlining its advantages.
  • docs/README.md
    • Updated the caching guide link description to mention DragonFly.
  • docs/observability.md
    • Updated tracing descriptions to include 'DragonFly/Redis traces'.
    • Modified the Docker Compose command for the Aspire profile to start DragonFly services instead of Valkey.
  • docs/testing.md
    • Updated test helper descriptions to refer to 'dragonfly' health registrations and 'DragonFly-backed' cache/DataProtection/TicketStore replacements.
  • infrastructure/dragonfly/haproxy.cfg
    • Added a new HAProxy configuration file to manage traffic routing to DragonFly master and replica instances.
  • infrastructure/kubernetes/dragonfly/README.md
    • Added new documentation detailing prerequisites, deployment steps, connection information, and operational aspects of DragonFly on Kubernetes.
  • infrastructure/kubernetes/dragonfly/dragonfly.yml
    • Added a new Kubernetes manifest for deploying a DragonFly instance with specified replicas, resources, and arguments.
  • infrastructure/observability/prometheus/rules/apitemplate-alerts.yml
    • Updated the APITemplateBackendHealthDegraded alert expression to monitor 'dragonfly' health instead of 'valkey'.
  • src/APITemplate.Api/Extensions/ApiServiceCollectionExtensions.cs
    • Renamed AddValkeyAndDataProtection to AddDragonflyAndDataProtection.
    • Updated the method to bind DragonflyOptions, parse connection string with new timeout options, and add DragonFly health checks.
    • Modified warning messages to reference Dragonfly:ConnectionString.
  • src/APITemplate.Api/Extensions/AuthenticationServiceCollectionExtensions.cs
    • Updated ConfigureCookieSessionStore to use DragonflyTicketStore.
  • src/APITemplate.Api/appsettings.Development.json
    • Renamed the 'Valkey' configuration section to 'Dragonfly'.
  • src/APITemplate.Application/Common/Options/DragonflyOptions.cs
    • Added a new DragonflyOptions class with ConnectionString, ConnectTimeoutMs, and SyncTimeoutMs properties.
  • src/APITemplate.Application/Common/Options/ValkeyOptions.cs
    • Removed the ValkeyOptions class.
  • src/APITemplate.Infrastructure/Security/DragonflyTicketStore.cs
    • Renamed ValkeyTicketStore.cs to DragonflyTicketStore.cs and updated the class name and comments accordingly.
  • tests/APITemplate.Tests/Integration/Helpers/TestConfigurationHelper.cs
    • Updated the default configuration to use Dragonfly:ConnectionString instead of Valkey:ConnectionString.
  • tests/APITemplate.Tests/Integration/Helpers/TestServiceHelper.cs
    • Modified RemoveExternalHealthChecks to remove 'dragonfly' health registrations.
    • Updated ReplaceOutputCacheWithInMemory, ReplaceDataProtectionWithInMemory, and ReplaceTicketStoreWithInMemory to remove/replace DragonFly-related services and options.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

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
Copy Markdown

@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 successfully replaces Valkey with DragonFly for caching and session storage. The changes are comprehensive, covering application code, configuration, documentation, testing, and infrastructure for both development (single-node) and production (HA with master-replica and proxy). The implementation is solid, introducing configurable timeouts for DragonFly connections and a resilient connection setup. I've found a couple of issues in the documentation where docker compose commands will fail due to referencing services from the wrong compose file. I've also included a suggestion to improve the clarity of memory limit configuration in the new Kubernetes manifest for DragonFly.

Comment thread README.md Outdated
```bash
# Start only the databases and Keycloak
docker compose up -d postgres mongodb keycloak valkey
docker compose up -d postgres mongodb keycloak dragonfly-master dragonfly-replica dragonfly-proxy
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The docker compose command references services (dragonfly-master, dragonfly-replica, dragonfly-proxy) that are defined in docker-compose.production.yml, not the default docker-compose.yml. This command will fail as-is. To use the HA setup for local infrastructure, you should specify the production compose file.

Suggested change
docker compose up -d postgres mongodb keycloak dragonfly-master dragonfly-replica dragonfly-proxy
docker compose -f docker-compose.production.yml up -d postgres mongodb keycloak dragonfly-master dragonfly-replica dragonfly-proxy

Comment thread docs/observability.md Outdated

```bash
ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak valkey alloy prometheus loki tempo grafana aspire-dashboard
ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak dragonfly-master dragonfly-replica dragonfly-proxy alloy prometheus loki tempo grafana aspire-dashboard
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

The docker compose command references services (dragonfly-master, dragonfly-replica, dragonfly-proxy) that are defined in docker-compose.production.yml, while other services in the command (like alloy and aspire-dashboard) are in the default docker-compose.yml. This will cause the command to fail. For a local development setup with observability, using the single dragonfly service from docker-compose.yml is more appropriate and resolves the conflict.

Suggested change
ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak dragonfly-master dragonfly-replica dragonfly-proxy alloy prometheus loki tempo grafana aspire-dashboard
ASPIRE_OTLP_GRPC_PORT=18889 ASPIRE_OTLP_HTTP_PORT=18890 docker compose --profile aspire up -d postgres mongodb keycloak-db keycloak dragonfly alloy prometheus loki tempo grafana aspire-dashboard

memory: 512Mi
args:
- "--maxmemory"
- "512mb"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The container memory limit is set to 512Mi (in limits), while the DragonFly maxmemory argument is set to 512mb. While 512mb (megabytes) is less than 512Mi (mebibytes), using the same number 512 can be confusing. To improve clarity and avoid potential misconfiguration, consider making the numbers different. For example, setting maxmemory to 500mb makes it explicit that it's below the container's 512Mi limit.

    - "500mb"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the template’s Redis-compatible backing services from Valkey to DragonFly across application code, test infrastructure, configuration, Docker/Kubernetes assets, and documentation.

Changes:

  • Replace Valkey-based caching/session-store wiring with DragonFly equivalents (options, DI registrations, health check name).
  • Update Docker Compose (dev + production HA topology with HAProxy) and add Kubernetes operator manifests/docs for DragonFly.
  • Refresh docs and test helpers to reference DragonFly configuration keys and components.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/APITemplate.Tests/Integration/Helpers/TestServiceHelper.cs Updates test DI helpers to remove/replace DragonFly-backed services during integration tests.
tests/APITemplate.Tests/Integration/Helpers/TestConfigurationHelper.cs Switches base test config key from Valkey to Dragonfly.
src/APITemplate.Infrastructure/Security/DragonflyTicketStore.cs Renames ticket store to DragonFly variant for BFF cookie session storage.
src/APITemplate.Application/Common/Options/ValkeyOptions.cs Removes Valkey options type.
src/APITemplate.Application/Common/Options/DragonflyOptions.cs Introduces DragonFly options with connection + timeout settings.
src/APITemplate.Api/Extensions/AuthenticationServiceCollectionExtensions.cs Registers DragonflyTicketStore as the cookie session store.
src/APITemplate.Api/Extensions/ApiServiceCollectionExtensions.cs Replaces Valkey wiring with DragonFly (multiplexer config, cache, data protection, health check).
src/APITemplate.Api/appsettings.Development.json Updates dev config section name to Dragonfly.
README.md Updates documentation references and diagrams from Valkey to DragonFly.
infrastructure/observability/prometheus/rules/apitemplate-alerts.yml Updates alert rule selector to use dragonfly health check label.
infrastructure/kubernetes/dragonfly/README.md Adds Kubernetes operator deployment instructions for DragonFly.
infrastructure/kubernetes/dragonfly/dragonfly.yml Adds DragonFly CR manifest for operator-managed HA.
infrastructure/dragonfly/haproxy.cfg Adds HAProxy TCP routing config for master/replica topology.
docs/testing.md Updates test helper documentation from Valkey to DragonFly.
docs/README.md Updates docs index entry to reference DragonFly in caching guide.
docs/observability.md Updates compose command and tracing wording from Valkey to DragonFly.
docs/CACHING.md Rewrites caching guide for DragonFly, including HA topologies and config keys.
docs/AUTHENTICATION.md Updates authentication/session-store diagrams and text from Valkey to DragonFly.
docker-compose.yml Replaces Valkey container with DragonFly for local dev compose.
docker-compose.production.yml Introduces DragonFly master/replica + HAProxy topology and updates API env var.
.vscode/tasks.json Updates VS Code task service list from valkey to dragonfly.
.vscode/launch.json Updates debug env var key from Valkey__ConnectionString to Dragonfly__ConnectionString.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +12 to +14

public int ConnectTimeoutMs { get; init; } = DefaultConnectTimeoutMs;

Comment thread docs/CACHING.md Outdated
- ./infrastructure/dragonfly/haproxy.cfg:/usr/local/etc/haproxy/haproxy.cfg:ro
```

The API connects to `dragonfly-proxy:6379`. Direct master access is available on port `6380` for debugging.
Comment thread docs/AUTHENTICATION.md Outdated
| `Keycloak__resource` | Client ID |
| `Keycloak__credentials__secret` | Client secret |
| `Valkey__ConnectionString` | Valkey/Redis connection string |
| `DragonFly__ConnectionString` | DragonFly/Redis connection string |
Comment thread README.md Outdated
Comment on lines 124 to 127
VK[(DragonFly)]
EF ---> DB
Mongo ---> MDB
REST -..-> VK
@zribktad zribktad merged commit b14e20b into main Mar 16, 2026
1 check passed
@zribktad zribktad deleted the feature/dragonfly branch March 16, 2026 21:09
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