We are designing a feature flag system that must be:
Consent-aware: Respect user consent (e.g., GDPR, CCPA) for features that process personal data.
Privacy scopes: Features may have different privacy requirements (e.g., data storage location, retention period).
Auditing: Need to track who changed flags, when, and why (for compliance).
Overrides: Ability to override flags for specific users, segments, or contexts (e.g., for debugging or emergency rollback).
We'll design a topology that includes:
Feature Flag Service: Core service to evaluate flags for a given user/context.
Consent Management: Integrated with a consent management platform (CMP) or internal consent records.
Privacy Scopes: Metadata attached to flags that define privacy constraints.
Audit Log: Immutable log of flag changes and evaluations (or at least changes).
Override Mechanisms: Rules that can override flag values based on conditions.
We'll break down the components:
Feature Flag Definition:
Each flag has:
key: unique identifier.
description: human-readable.
defaultValue: default boolean or multivariate value.
privacyScope: (optional) an identifier referencing a privacy policy or set of constraints (e.g., "EU_ONLY", "NO_PII").
consentRequired: boolean or a consent type (e.g., "marketing", "analytics") that must be granted by the user.
auditEnabled: boolean to indicate if changes to this flag are audited (likely always true for consent-aware flags).
Consent Management Integration:
The flag evaluation context must include the user's consent status for relevant consent types.
We assume we have a way to look up user consent (via user ID, session, etc.). This could be a separate service or a cached consent status in the evaluation context.
If a flag requires consent and the user hasn't granted it, the flag should be disabled (return default or safe value) regardless of other rules.
Privacy Scopes:
When a flag is evaluated, we must check if the current context (e.g., user's location, data residency) complies with the privacy scope.
Example: If flag has privacyScope "EU_ONLY", then only users in the EU can have it enabled. Otherwise, disabled.
Privacy scopes might be defined as a set of rules (e.g., country in [EU], data center in [EU]) that are evaluated in the context.
Override Rules:
We need a way to specify conditions that override the flag value. Overrides can be:
User-specific (by user ID, or user attributes)
Segment-based (e.g., "beta_testers")
Global (e.g., emergency disable)
Overrides might be stored as separate rules that are evaluated before the main flag rules? Or as part of the flag's rule set? We'll treat them as a separate layer that has highest priority.
Overrides should also be consent and privacy aware? Actually, overrides might be used for emergency, so they might bypass consent? We need to decide:
Typically, overrides for debugging might bypass consent? But for compliance, we might want that even overrides respect consent and privacy?
Let's assume: Overrides are for operational control and can be set by authorized personnel. However, if an override would enable a feature that requires consent and the user hasn't given consent, we must not enable it? Or maybe we allow it but then we are violating consent?
To be safe, we should design so that overrides cannot bypass consent and privacy scopes? Actually, in an emergency (like a bug), we might need to turn off a feature for a specific user even if they consented? That is okay because we are disabling. But enabling a feature that requires consent without consent is bad.
So: Overrides can only set the flag to a value that is allowed by consent and privacy? Or we allow overrides to set any value but then we have an additional check: after override, we still run consent and privacy checks? That would mean overrides cannot bypass consent and privacy. That seems safer.
Proposed order of evaluation:
a. Check overrides: if any override condition matches, set the flag to the override value. But then we must check if that value is allowed by consent and privacy? Or we can have overrides that are themselves conditional on consent? Better: after applying override, we still evaluate consent and privacy? Actually, we want overrides to be able to force a value regardless of targeting rules, but we don't want to violate consent. So we should have:
If override value is true but user hasn't consented -> then we should treat as false? Or we should not allow such override?
I think we should not allow an override that would enable a feature without consent. So the override rule should only be able to set the flag to a value that is permitted by the consent and privacy checks. Alternatively, we can design the override to only override the "targeting" part, but then consent and privacy are checked after. So the override can set the flag to true but then if consent is missing, it becomes false. That means the override didn't fully override. That might be confusing.
Auditing:
We need to audit:
a. Changes to flag definitions (including default, privacy scope, consent required, etc.)
b. Changes to override rules.
c. Possibly, flag evaluation outcomes? But that might be too much. Usually, we audit configuration changes and maybe significant evaluation overrides?
We should have an audit log that records:
Who (user/service) made the change.
When.
What changed (old and new values).
Why (reason, ticket number, etc.)
The audit log should be immutable and stored securely.
Topology:
We'll have the following services/components:
Flag Configuration Service: Stores and serves flag definitions, override rules, and privacy scope definitions. This service must ensure that changes are audited.
Consent Service: Provides consent status for a user (by user ID or anonymous ID). This might be a separate existing service.
Evaluation Service: Given a context (user ID, attributes, location, etc.), evaluates a flag. It will:
Fetch the flag definition (from config service or cache).
Check privacy scope: evaluate the privacy scope rules against the context. If fail, return false.
Check consent: if flag requires consent, check consent status for the user (from consent service). If not granted, return false.
Check overrides: fetch applicable override rules (maybe cached) and see if any matches the context. If match, return the override value.
Evaluate targeting rules (percentage, attributes, etc.) to determine value.
Audit Log Service: Receives audit events from the configuration service and possibly from the evaluation service (if we want to log overrides applied? but that could be high volume). We might log only configuration changes and maybe significant overrides (like global overrides). We can decide to log every override application? That might be too much. Instead, we can log when an override rule is created, updated, or deleted. And we can also log when a flag evaluation is forced by an override? But that could be millions per day. So maybe we log only the configuration changes and have a separate way to trace which overrides were applied for a given user (by storing the override rule ID in the evaluation response for debugging? but that might be sensitive). Alternatively, we can have an audit trail that records when an override rule is evaluated and returned, but only for critical flags? That gets complex.
Given the volume, we might limit auditing to configuration changes and maybe have a separate monitoring system that tracks the usage of override rules (counts, etc.) without logging each instance.
So: Audit Log Service will store:
Flag definition changes (create, update, delete).
Override rule changes (create, update, delete).
Privacy scope changes (if separate).
Possibly, changes to consent requirements.
We might also want to log when a flag is evaluated with an override? For compliance, we might need to prove that we did not enable a feature without consent. Since we have the evaluation logic, if we log the configuration changes and the evaluation logic is deterministic, we can replay? But that might not be feasible. So maybe we log the evaluation outcome for a sample of users? Or we log when an override is applied?
Data Storage:
Flag Configuration: Store in a database (e.g., PostgreSQL) with tables for flags, override rules, privacy scopes.
Audit Log: Use an append-only store (like a separate database with immutable tables, or a log-based system like Kafka + immutable storage).
Cache: The evaluation service will cache flag definitions and override rules (with TTL) to avoid hitting the config service for every evaluation.
APIs:
Flag Configuration API: for creating/updating flags, override rules, privacy scopes. Must require authentication and authorization. Every mutating call emits an audit event.
Evaluation API: POST /evaluate with context (user ID, attributes, location, etc.) and list of flag keys. Returns a map of flag keys to values (and maybe metadata like reason: "override", "targeting", etc. for debugging). This API should be high performance and cached.
Consent Service API: to get consent status for a user.
Security:
Only authorized personnel can change flag configurations and override rules.
Audit logs must be tamper-proof.
Evaluation API should be rate-limited and protected against abuse.
Privacy by Design:
By default, flags that process personal data should have privacyScope and consentRequired set.
The system should enforce that any flag that has privacyScope or consentRequired cannot be evaluated without the necessary context (user location, consent status). If the context is missing, return false? Or error? Better to return false to be safe.
Example Flow:
User request comes in, we have user ID and some attributes (like IP address for geolocation).
The evaluation service must be stateless and scalable.
Cache invalidation: when flag definitions change, need to invalidate cache. Could use pub/sub to notify evaluation service instances.
Override rules might be stored separately and cached.
Privacy scope rules might be complex; we need a rule engine (like a DSL) to evaluate conditions (e.g., "country in ['EU']", "data_center == 'eu-west-1'").
Extensibility:
The system should allow adding new privacy scopes and consent types without code changes (configuration-driven).
Override conditions should be expressive (like targeting rules).
Monitoring and Alerting:
Monitor evaluation latency, cache hit rates.
Alert on unusual spike in override applications (might indicate misuse).
Deployment:
Evaluation service deployed close to application (same region) to reduce latency.
Configuration service and audit log can be centralized.
But actually, the Evaluation Service fetches from Config Service the flag definitions and override rules. The Config Service stores them in DB and publishes audit events to Audit Log. The Evaluation Service caches these.
We might also have a separate Admin UI that talks to Config Service.
Let's write a more formal plan:
Component: Flag Configuration Service
REST/GraphQL API for managing flags, override rules, privacy scopes.
Existing service that stores user consent records (e.g., in a separate DB). Provides an API: GET /consent?userId=...&type=... returning boolean and timestamp.
We assume this service is already audited for consent changes.
Component: Evaluation Service
API: POST /evaluate with body: { userId: string, attributes: object, flags: string[] }
Fetch flag definition (from cache or config service). If not found, treat as false? Or error? We'll treat as false and maybe log warning.
Evaluate privacy scope: if flag has privacyScope, fetch the privacy scope rule and evaluate against context (user attributes, location). If fails, set value=false, reason='privacy_failed'.
If privacy passed, evaluate consent: if flag requires consent, call consent service (or use cached consent status from context? We need to get consent status for the user. The evaluation request might include consent status? But that would trust the client. Better to fetch from consent service using the user ID. However, that adds latency. We can have the application pass the consent status as part of the context? But then the application could lie. So we must fetch from consent service. But that makes evaluation service call consent service for every request? That could be heavy. We can have the application include a JWT with consent claims? And we verify the JWT? That might be better: the consent service issues a token that includes consent status, and the evaluation service verifies it. Or we have a separate consent cache that the evaluation service can query quickly. Let's assume we have a fast consent cache (like Redis) that is kept up to date by the consent service. Then evaluation service checks that cache.
If consent passed, check override rules: fetch applicable override rules for the flag (from cache) and evaluate conditions against context. If any override rule matches (and is active based on start/end dates), then use the override value. We need to handle multiple matches? We can have priority. Then set value=override.value, reason='override'. Also, log an audit event to Audit Log Service (asynchronously) with: userId, flagKey, overrideRuleId, timestamp, value.
If no override, evaluate targeting rules (stored in flag definition, e.g., percentage, user attributes). Set value accordingly, reason='targeting'.
Cache: flag definitions and override rules cached with TTL (e.g., 1 minute) and also invalidated by config service via pub/sub on changes.
Component: Admin UI
Web interface for managing flags, override rules, privacy scopes. Uses Config Service API. Shows audit logs.
Audit Log Service
Simple service that receives audit events (via HTTP or from a message queue) and writes to immutable storage (e.g., write-once database, or append-only file, or blockchain? but we don't need blockchain). Could be just a separate table with restricted write access.
Data Flow:
Admin changes a flag via Admin UI -> Config Service -> writes to DB and emits audit event -> Audit Log Service stores it.
Config Service notifies Evaluation Service instances (via pub/sub) to invalidate cache for that flag.
User request -> App calls Evaluation Service with context.
Evaluation Service:
Tries cache: if miss, fetches from Config Service (which might also be cached in a shared cache).
Performs evaluation as above.
If override applied, sends async audit event to Audit Log Service.
Returns result.
Consent service updates: when user consent changes, consent service updates its cache and possibly notifies? Not needed for evaluation unless we want real-time. We can have evaluation service read from consent cache with short TTL.
Security:
All internal services communicate via TLS and mutual authentication (mTLS) or using a service mesh.
Admin UI uses OAuth2/OIDC.
Scalability:
Evaluation Service is stateless and can be scaled horizontally.
Use read replicas for Config Service DB if needed.
Cache (Redis) shared among evaluation service instances.
Privacy and Compliance:
By design, flags without privacy scope and consent requirement can be evaluated without user context? But we still need user context for targeting? Actually, we might have flags that are not user-specific (e.g., feature available to all users in a region). But our evaluation still needs some context (like location) for privacy. So we require at least the minimum context to evaluate privacy and consent. For a flag with no privacy and no consent, we might not need any user data? But we still might want targeting based on user attributes. So we require the application to provide attributes? We can require that the evaluation request includes at least the necessary context for the flag's privacy and consent. If missing, we return false? That might break functionality. So we should design: if a flag has privacy or consent requirements, then the evaluation request must include the necessary data (like user ID, location, etc.). If missing, we return false and reason='missing_context'. Or we could error. We'll return false and log a warning.
For flags without privacy/consent, we can evaluate with minimal context? Possibly just user ID for targeting? But if no user ID, we might still want to evaluate based on request attributes? We'll design the rule engine to evaluate conditions that may depend on available context. If a condition requires an attribute that is missing, we treat as false? That might be complex. We'll assume the application provides all necessary context.
Override Rule Conditions:
We need a rule language. We can reuse the same as targeting rules? Possibly. We can have a DSL that evaluates against the context (a JSON object). For example: user.country == 'US' && user.id == '123'. We'll use a safe evaluation engine (like a expression parser) that doesn't allow arbitrary code execution.
Privacy Scope Rules:
Similar DSL, but might be simpler (e.g., country in ['EU']). We can use the same engine.
Consent:
The consent type is a string (e.g., "analytics", "marketing"). The consent service can check if the user has granted that specific type.
Overrides Priority:
If multiple override rules match, we need a priority (e.g., higher priority overrides lower). We can add a priority field (integer) to override rules. Default 0. Higher number wins.
Temporary Overrides:
Start and end dates allow temporary overrides (e.g., for a week).
Example Use Case:
Flag: "new_feature_x"
privacyScope: "EU_ONLY"
consentRequired: "analytics"
default: false
targeting: 10% rollout based on user.id hash.
Override rule: for user "123", force enable until next week.
Evaluation for user "123" in Germany with analytics consent:
Evaluation for user "456" in Germany with analytics consent:
Privacy pass.
Consent pass.
Override: no match.
Targeting: hash("456") mod 100 < 10? If yes, true, else false.
Evaluation for user "789" in US with analytics consent:
Privacy: US not EU -> fail -> return false.
Evaluation for user "123" in US with analytics consent:
Privacy fail -> return false (override not considered).
Audit Example:
Admin creates override rule for user "123" to enable flag "new_feature_x". Audit log: entityType='override_rule', action='CREATE', entityId=..., updatedBy=admin, reason="testing for user 123".
When evaluation happens for user "123", Evaluation Service sends async audit: entityType='override_application', entityId=null? We need to design: we can have a separate audit event type. Perhaps we have an audit_events table with a event_type field. For configuration changes, event_type='config_change'. For override application, event_type='override_applied'. And we log: flagKey, overrideRuleId, userId, timestamp, value.
Open Questions:
How to handle multivariate flags (more than boolean)? We can extend the value to be a string or number. The same logic applies.
How to handle targeting rules that are complex (like nested conditions)? We need a rule engine that can evaluate arbitrary expressions. We can use a library like govaluate or jsonlogic? We'll design the condition DSL to be a subset of JavaScript? Or use a safe expression evaluator.
Given the complexity, we might limit conditions to simple AND/OR of comparisons. But we can design for extensibility.
Implementation Plan:
We'll build in phases:
Phase 1: Core flag evaluation without consent and privacy.
Phase 2: Add privacy scopes and consent checks.
Phase 3: Add overrides.
Phase 4: Add auditing.
But since they are intertwined, we might design the full system and implement incrementally.
Given the instruction is to plan, we have provided a comprehensive design.
Now, we need to output the plan in a clear, structured manner. We'll produce:
Overview
Core Concepts
Components
Data Model
Evaluation Flow
Auditing
Security
Scalability
Example
Open Questions/Considerations
Let's write it up.
Consent-Aware Feature Flag Topology: Design Plan
1. Overview
A feature flag system that respects user consent (e.g., GDPR, CCPA), enforces privacy scopes, provides full auditing, and supports controlled overrides. The design ensures privacy and compliance are baked into the evaluation pipeline, with clear separation of concerns and auditability.
2. Core Concepts
Flag: A toggle or multivariate setting controlling a feature. Each flag has metadata:
key: unique identifier.
defaultValue: fallback value (bool, string, number, etc.).
privacyScopeId: reference to a privacy scope (nullable).
consentRequired: consent type string (e.g., "analytics") or null.
targetingRules: conditions for rollout (percentage, user attributes, etc.).
Privacy Scope: A reusable set of conditions that must be satisfied for a flag to be enabled (e.g., country in ['EU']). Stored as a rule expression.
Consent: User's explicit permission for a specific purpose. Verified via a Consent Service.
Override Rule: A high-priority rule that forces a flag value for specific contexts (user, segment, time-bound). Conditions are rule expressions.
Audit Event: Immutable record of configuration changes or override applications.
3. System Components
3.1 Flag Configuration Service
Purpose: Manage flag definitions, privacy scopes, and override rules.
APIs: REST/GraphQL for CRUD operations.
Storage: Relational DB (e.g., PostgreSQL) with tables:
Cache: In-memory or Redis cache for flag definitions and override rules (TTL ~1 min). Pub/sub-based invalidation from Config Service.
Evaluation Pipeline (per flag):
Fetch Definition: From cache or Config Service.
Privacy Check: If flag has privacyScopeId, evaluate the privacy scope’s rule expression against context (user attributes, geolocation, etc.). If fails → value = false, reason = "privacy_failed".
Consent Check: If consentRequired is set, query Consent Service (or a cached consent snapshot). If not granted → value = false, reason = "consent_failed".
Override Check: If privacy and consent passed, fetch active override rules for the flag. Evaluate conditions in order of descending priority. First match → value = override.value, reason = "override". Async audit: Emit override_applied event (userId, flagKey, overrideRuleId, value, timestamp).
Targeting: If no override, evaluate targetingRules (e.g., percentage rollout, attribute conditions). → value = ..., reason = "targeting".
Missing Context: If a required attribute for any condition is missing, treat as condition failure (e.g., privacy fails → false). Log warning.
Consent Cache: Short-lived (e.g., 5 min) cache of user consent status to reduce load on Consent Service.
3.4 Audit Log Service
Purpose: Immutable storage of audit events.
Input: Receives events from Config Service (config changes) and Evaluation Service (override applications).
Storage: Append-only database (e.g., Kafka + immutable store, or a PostgreSQL table with row-level security and no DELETE/UPDATE).
Query API: For compliance audits (e.g., "show all changes to flag X in last quarter", "list overrides applied to user Y").
3.5 Admin UI
Web interface for managing flags, privacy scopes, overrides, and viewing audit logs.
Authenticated via OAuth2/OIDC with role-based access control (e.g., only compliance officers can view audit logs).
4. Rule Expression Language (DSL)
A safe, deterministic expression evaluator (e.g., based on JSONLogic or a custom AST parser) operating on a context object:
Context includes: userId, user (attributes), request (IP, user-agent), environment (data center, region).
Constraints: No side effects, no network calls, deterministic.
5. Data Flow
Configuration Change:
Admin → Admin UI → Config Service → DB + Audit Log Service.
Config Service publishes cache invalidation message (e.g., Redis Pub/Sub) to all Evaluation Service instances.
Flag Evaluation:
Application → Evaluation Service with user context.
Evaluation Service:
Checks cache for flag/overrides; fetches from Config Service on miss.
Runs evaluation pipeline.
If override applied, sends async audit event to Audit Log Service.
Returns result.
Consent Verification:
Evaluation Service checks local consent cache; on miss, calls Consent Service and caches result.
6. Auditing Strategy
Configuration Changes: Every create/update/delete of flags, privacy scopes, override rules is logged with user, timestamp, old/new values, and reason.
Override Applications: Each time an override rule determines a flag’s value, log the event (userId, flagKey, overrideRuleId, value, timestamp). This provides accountability for manual interventions.
Compatibility: The combination of immutable configuration history and override application logs allows reconstruction of any flag’s state at any time, with ability to trace human decisions.
7. Security & Compliance
Authentication & Authorization:
Config Service APIs: require service-to-service mTLS or API keys.
Admin UI: OAuth2 with roles (admin, auditor, developer).
Data Minimization: Evaluation context only includes necessary attributes; sensitive PII avoided where possible.
Consent Enforcement: Hard gate—flags requiring consent are always disabled if consent missing, regardless of overrides. Overrides can only force false or trueafter consent/privacy checks pass.
Privacy by Design: Flags without explicit privacy scope default to no restrictions? Actually, we require explicit definition. If a flag processes personal data, it must have a privacy scope and consent requirement. The Config Service can enforce this via validation (e.g., linting on save).
Audit Integrity: Audit logs are append-only; stored with cryptographic hashing (e.g., Merkle tree) if required for non-repudiation.
Override rule for analytics_feature sets value true for user test_user.
User test_user in EU but without analytics consent:
Privacy pass.
Consent fail → false (override never checked). No audit event for override application.
10. Open Questions & Mitigations
Consent Cache Staleness: How fresh must consent data be? TTL of 5 min balances load/accuracy. For real-time revoke, Consent Service can push purge messages to Evaluation Service caches.
Rule Complexity: Avoid overly complex expressions; provide testing UI in Admin UI to validate expressions against sample contexts.
Audit Volume: Override application logs could be high. Consider sampling or rate-limiting logs for high-traffic flags, but ensure compliance-critical flags are fully logged.
Multivariate Flags: Extend value to support any JSON type; override and targeting rules must produce same type.
Geo-IP Accuracy: Privacy scope may rely on geolocation. Use a trusted GeoIP database; fallback to privacy_failed if unavailable.
11. Deployment & Ops
Environments: Separate Config/Audit services per environment (staging, prod). Evaluation services deployed per region (close to app).
Monitoring:
Evaluation latency, cache hit rates.
Override application rate (alerts on spikes).
Consent service errors.
Disaster Recovery: Audit logs replicated across regions; Config Service DB backed up daily.
Compliance Reports: Build a query tool on top of Audit Log Service to generate reports (e.g., "list all users for whom Flag X was enabled without consent in Q1").
This topology ensures that privacy and consent are non-bypassable gates, overrides are fully audited, and the system scales for high-volume evaluation. The separation of configuration, evaluation, and auditing allows independent scaling and clear accountability.
Alternatively, we can have a hierarchy:
First, evaluate if the user meets the privacy scope and consent. If not, the flag is immediately false (or safe value) and no other rules apply.
Then, if the user passes privacy and consent, we apply overrides and then targeting rules? But then overrides can only set to true if consent and privacy are already satisfied? That doesn't allow overriding to false for a user who otherwise would have true? Actually, we want overrides to be able to force false even if targeting and consent are okay (for emergency disable). So:
Proposed evaluation order:
Privacy Scope Check: if the context does not satisfy the flag's privacy scope, return false (or safe value) and stop.
Consent Check: if the flag requires consent and the user hasn't granted it, return false (or safe value) and stop.
Override Rules: if any override rule matches, return the override value (which could be true or false). Note: if the override value is true, we already passed privacy and consent, so it's okay. If the override value is false, we are forcing disable.
Targeting Rules: if no override, evaluate the flag's targeting rules (like percentage rollout, user attributes, etc.) to determine the value.
But what if we want to override to true for a user who is outside the privacy scope? We shouldn't allow that because it violates privacy. So step 1 and 2 are hard gates. Overrides can only work if the user already satisfies privacy and consent? Actually, if we want to override for a specific user in a non-EU country to have an EU-only feature, that would be a privacy violation. So we should not allow that. Therefore, step 1 and 2 are absolute: if they fail, the flag is disabled regardless of overrides.
However, what if the privacy scope is "NO_PII" and the user is in a country that requires PII to be stored locally? Actually, the privacy scope is about the feature's requirements. If the feature requires data to be stored in the EU, and the user is in the US, we cannot enable it for that user because we might not have EU infrastructure for that user? Or we might have, but the user's data would be stored in the US? So we must not enable. So step 1 is absolute.
So:
Privacy scope and consent are preconditions. If not met, flag is disabled.
Then overrides can only set to true if the preconditions are met? Actually, overrides can set to false even if preconditions are met (to force disable). But they cannot set to true if preconditions are not met because we already returned false. So in the override step, we are only considering overrides for users who passed preconditions? That means if we want to force-enable a feature for a user who is in the EU and has consented, we can override to true. But if the user is in the US and the feature is EU_ONLY, we cannot override to true because the precondition fails and we never get to override.
This seems safe.
Let's think: Compliance might require us to show that for a given user, we respected their consent. If we have an audit log of configuration changes and we have the evaluation logic, we can theoretically reconstruct the state at any time. But if we have overrides that are temporary, we need to know when they were active. So we should log when an override rule becomes active and when it expires? That is already in the override rule change audit. But we also need to know for a specific user at a specific time, what was the flag value? That is a query we might need to support. So we might need to store evaluation results? That's a lot of data.
Alternative: We can store a short-term cache of evaluations? Or we can have the evaluation service log every evaluation to a separate audit log? But that's huge.
Compromise: For high-risk flags (those with privacy scope or consent required), we log every evaluation? That might be too heavy. Instead, we can log every time an override is applied (i.e., when the evaluation result is determined by an override rule). Because that is a manual intervention and we want to track when we override. For normal targeting evaluations, we don't log each one. But then we cannot prove for a specific user that they were not enabled without consent? Actually, if the flag is not overridden and the user didn't consent, the evaluation should return false. We don't log that, but we can show that the configuration at that time required consent and the user didn't consent (by querying consent service). But consent service might not log every check? We need to design the consent service to provide audit of consent status changes? And we need to be able to prove that at a given time, the user had not consented? That might require consent service to store historical consent records? That is a separate problem.
Given the complexity, let's assume we are only auditing configuration changes and override rule applications. We'll design the evaluation service to emit an audit event when an override is applied (i.e., when the result comes from an override rule). For normal evaluations, no audit event.
But what about when a flag is changed and we want to know who turned it on for a user? That might be a combination of configuration and targeting rules. Without logging each evaluation, we cannot reconstruct. So maybe we need to log every evaluation for consent-aware flags? That could be a requirement for GDPR: proof of consent for data processing. So we might need to log for each user and each flag that requires consent, whether we evaluated it and what the result was, and the reason (consent missing, override, targeting, etc.). That is a lot of data but for compliance it might be necessary.
Given the scope, we might not want to store every evaluation indefinitely. We could store for a limited time (e.g., 2 years) and then purge. Or we could store aggregated statistics.
Let's assume our requirement is to have an audit trail for configuration changes and for any manual overrides (because those are human decisions). For automated evaluations, we trust the system and we have the consent status logs separately.
So we'll design:
Audit Log Service: receives events from:
Flag Configuration Service: on create/update/delete of flags, override rules, privacy scopes.
Evaluation Service: when an override rule is applied (i.e., the evaluation result was set by an override). We log: user ID (or anonymous ID), flag key, override rule ID, timestamp, and the value set by override.
We might also want to log when a flag is evaluated and the result is true due to targeting? But that is not a manual action, so maybe not necessary.
But for compliance, we might need to show that we only process data when consent is given. So we need to prove that for a given user and a given flag that requires consent, we only enabled it if they consented. That proof would come from:
The flag definition at that time required consent.
The consent service logs that the user had given consent at that time.
The evaluation service did not log an override that forced it to true without consent? Actually, if an override forced it to true and the user hadn't consented, that would be a violation. But our evaluation logic prevents that because we check consent before overrides? Wait, we said overrides are after consent check. So if the user hasn't consented, we never get to overrides. So an override cannot force a true without consent. So we are safe.
Therefore, we don't need to log every evaluation. We only need to log when an override rule is applied (and we know that the user must have consented and satisfied privacy scope to get to that point). But what if the override rule sets to false? That's fine, it's just disabling.
So we log override applications for accountability (who set up the override that affected this user).