AlgoMaster Logo
AlgoMasterAudit a Blue-Green Cutovermedium

Audit a Blue-Green Cutover

medium

A blue-green deployment keeps the old environment available while a new one is verified, switched into service, and drained.

Design a BlueGreenCutoverAuditor:

  • The constructor receives the number of long-lived connections already attached to blue.
  • firstUnsafeEvent(events) returns the first unsafe event index, or -1.
  • isComplete(events) returns true only when a valid trace has green active and blue retired.

Recognized events:

  • "DEPLOY_GREEN" creates the green environment.
  • "SMOKE_PASS" records successful smoke tests after deployment.
  • "SCHEMA_COMPATIBLE" confirms the shared database works with both versions.
  • "SWITCH_GREEN" sends new traffic to green after all readiness gates pass.
  • "DRAIN_BLUE" closes one pre-existing blue connection after the switch.
  • "ROLLBACK_BLUE" returns new traffic to retained blue.
  • "RETIRE_BLUE" removes blue after green is active and every old connection has drained.

Setup events may occur only once. A rolled-back trace is valid but incomplete. Green remains deployed and may be switched to again.

Example 1:

Input:

Output:

Example 2:

Input:

Output:

Constraints

  • 0 <= activeBlueConnections <= 10^4
  • 0 <= events.length <= 10^5
  • Event names are case-sensitive.
  • At most 100 total method calls are made.
Hints

Loading...
CallReturns
new BlueGreenCutoverAuditor(2)null
firstUnsafeEvent(["DEPLOY_GREEN","SMOKE_PASS","SCHEMA_COMPATIBLE","SWITCH_GREEN","DRAIN_BLUE","DRAIN_BLUE","RETIRE_BLUE"])-1
isComplete(["DEPLOY_GREEN","SMOKE_PASS","SCHEMA_COMPATIBLE","SWITCH_GREEN","DRAIN_BLUE","DRAIN_BLUE","RETIRE_BLUE"])true

Green passes both gates, receives new traffic, the two existing blue connections drain, and only then is blue retired.

Run checks these cases. Submit also runs a larger hidden set.