Skip to content

Flip DeterministicGuid default to XxHash128 (v2) in v11 #7734

@danielmarbach

Description

@danielmarbach

In v10, the AppContext switch NServiceBus.Core.Hosting.UseV2DeterministicGuid must be explicitly set to true to opt into the new DeterministicGuid (XxHash128-based). The default remains the legacy MD5-based algorithm. In v11, this should be flipped: XxHash128 becomes the default, and users who need to preserve their existing MD5-based host IDs must explicitly set the switch to false.

Motivation

  • MD5 is a cryptographic hash that is unnecessarily expensive for generating deterministic GUIDs and can cause FIPS compliance issues (see the comment in HostingComponent.Settings.cs:118).
  • XxHash128 is non-cryptographic, faster, and produces well-distributed GUIDs with proper v8/RFC 9562 formatting.
  • The new implementation has been available since v10 with an explicit opt-in. v11 is the right time to make it the default while still offering a backward-compatible escape hatch.

Changes Required

  1. Flip the AppContextSwitches.UseV2DeterministicGuid default
    In AppContextSwitches.cs, change the logic so that the switch defaults to true (use v2) unless explicitly set to false:
// Before (v10): returns true only when switch is explicitly enabled
state = AppContext.TryGetSwitch(UseV2DeterministicGuidSwitchName, out var isEnabled) && isEnabled
    ? SwitchState.Enabled
    : SwitchState.Disabled;
// After (v11): returns true unless switch is explicitly disabled
state = AppContext.TryGetSwitch(UseV2DeterministicGuidSwitchName, out var isEnabled) && !isEnabled
    ? SwitchState.Disabled
    : SwitchState.Enabled;
  1. Invert the warning in HostingComponent.Initialize
    The current warning tells users how to opt into v2. It should be inverted to warn users who are on the legacy path that they should migrate, and that the legacy class will be removed in v12.
  2. Rename the switch constant**
    Consider renaming UseV2DeterministicGuidSwitchName to something like UseLegacyDeterministicGuidSwitchName (or keeping the old name as a compat alias) so the name reflects the new semantics: setting it to true means "use the old MD5 algorithm". Update the documentation strings, environment variable guidance, and UsedLegacyDeterministicGuidSettingsKey accordingly.
  3. Update HostingComponent.Settings.GenerateHostId
    Invert the branch: the default path uses DeterministicGuid.Create, and only when the switch explicitly opts into legacy does it use LegacyDeterministicGuid.Create.
  4. Update PreObsolete on LegacyDeterministicGuid
    The annotation already marks it for removal in v12 with DeterministicGuid as the replacement. No change needed there.

Breaking Change

This is a host ID breaking change for endpoints that do not explicitly set the switch. Endpoints that rely on the MD5-based host ID (e.g., for correlating with existing ServicePulse entries) will get a new host ID after upgrading unless they set:

AppContext.SetSwitch("NServiceBus.Core.Hosting.UseV2DeterministicGuid", false);

Or via environment variable (.NET 9+): DOTNET_NServiceBus_Core_Hosting_UseV2DeterministicGuid=false

Follow-up (v12)

Remove LegacyDeterministicGuid and the AppContext switch entirely.

References

  • src/NServiceBus.Core/AppContextSwitches.cs — switch logic
  • src/NServiceBus.Core/Hosting/HostingComponent.Settings.csGenerateHostId branch
  • src/NServiceBus.Core/Hosting/HostingComponent.cs — startup warning
  • src/NServiceBus.Core/Utils/LegacyDeterminsticGuid.cs — legacy implementation (marked PreObsolete, remove in v12)
  • src/NServiceBus.Core/Utils/DeterministicGuid.cs — current XxHash128-based implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions