Compliance
GDPR
CCPA
Privacy
Compliance
+3 more

GDPR & CCPA Compliance for Developers: Privacy-by-Design Implementation Guide

SCR Security Research Team
January 26, 2026
20 min read
Share

Why Developers Need to Know Privacy Law

Privacy regulations don't just affect lawyers and compliance officers. Developers make the architectural decisions that determine whether an application is compliant or not. Every database schema, API response, logging configuration, and analytics integration has privacy implications.

The Financial Risk: GDPR fines reached €2.1 billion in 2024 (GDPR Enforcement Tracker). Meta alone was fined €1.2 billion for illegal data transfers. Under CCPA/CPRA, California's Attorney General has enforcement power with fines of $7,500 per intentional violation — per user, per incident.


GDPR vs CCPA/CPRA Comparison

RequirementGDPR (EU)CCPA/CPRA (California)
ScopeAny entity processing EU residents' dataBusinesses with CA consumers meeting revenue/data thresholds
ConsentOpt-in required (explicit consent)Opt-out model (default collect, right to opt out)
Right to accessYes (Article 15)Yes (§1798.110)
Right to deleteYes (Article 17)Yes (§1798.105)
Data portabilityYes (Article 20)Yes (§1798.130)
Data minimizationYes (collect minimum necessary)No explicit requirement
Privacy by designMandatory (Article 25)Recommended but not mandatory
DPO requiredYes (for certain entities)No
Breach notification72 hours to DPA"Without unreasonable delay"
FinesUp to €20M or 4% global revenue$2,500-$7,500 per violation

Privacy-by-Design Patterns

1. Data Minimization in Database Schema

// BAD — Collecting more data than needed
interface User {
  id: string;
  email: string;
  fullName: string;
  dateOfBirth: Date;      // Do you actually need this?
  phoneNumber: string;     // Is this required for the service?
  homeAddress: string;     // Why are you storing this?
  socialSecurityNumber: string;  // Almost never needed
  ipAddress: string;       // Collecting without purpose?
  browserFingerprint: string;   // Unnecessary tracking
}

// GOOD — Minimum data required for service delivery
interface User {
  id: string;              // Internal identifier (UUID)
  email: string;           // Required for account (hashed for search)
  displayName: string;     // User-chosen, not real name
  createdAt: Date;         // Account creation timestamp
  consentTimestamp: Date;  // When consent was given
  consentVersion: string;  // Which privacy policy version
  dataRetentionDate: Date; // When to auto-delete
}

2. Right to Erasure (Right to Be Forgotten)

// Implement GDPR Article 17 — Right to Erasure
async function deleteUserData(userId: string): Promise<DeletionReport> {
  const report: DeletionReport = {
    userId,
    requestedAt: new Date(),
    systems: [],
  };

  // 1. Primary database
  await User.findByIdAndDelete(userId);
  report.systems.push({ system: "users_db", status: "deleted" });

  // 2. Related records
  await Order.updateMany({ userId }, { $set: { userId: "DELETED" } });
  report.systems.push({ system: "orders_db", status: "anonymized" });

  // 3. Comments / posts
  await Comment.deleteMany({ userId });
  report.systems.push({ system: "comments_db", status: "deleted" });

  // 4. Analytics
  await Analytics.deleteMany({ userId });
  report.systems.push({ system: "analytics", status: "deleted" });

  // 5. Search indices
  await searchIndex.delete(userId);
  report.systems.push({ system: "search_index", status: "deleted" });

  // 6. Backups — Flag for exclusion from restore
  await BackupExclusion.create({ userId, excludeFrom: new Date() });
  report.systems.push({ system: "backups", status: "flagged_for_exclusion" });

  // 7. Third-party services
  await stripe.customers.del(userId);
  report.systems.push({ system: "stripe", status: "deleted" });

  // 8. Logs — Cannot delete, but redact PII
  await LogRedaction.create({ userId, redactBefore: new Date() });
  report.systems.push({ system: "logs", status: "scheduled_for_redaction" });

  // Generate deletion certificate
  report.completedAt = new Date();
  report.certificateId = generateCertificateId();

  return report; // Store report for compliance audit
}
// Consent record schema
interface ConsentRecord {
  userId: string;
  consentType: "marketing" | "analytics" | "third_party_sharing" | "essential";
  granted: boolean;
  timestamp: Date;
  method: "explicit_checkbox" | "cookie_banner" | "settings_page";
  policyVersion: string;
  ipAddress?: string;  // For proof of consent
  withdrawable: boolean;
}

// Check consent before processing
async function canProcessData(userId: string, purpose: string): Promise<boolean> {
  const consent = await Consent.findOne({
    userId,
    consentType: purpose,
    granted: true,
  });

  if (!consent) return false;

  // Check if consent is still valid (policy hasn't changed)
  if (consent.policyVersion !== currentPolicyVersion) return false;

  return true;
}

4. Data Subject Access Request (DSAR)

// GDPR Article 15 — Right of Access
// Must respond within 30 days
async function generateDSAR(userId: string): Promise<DSARReport> {
  const report = {
    generatedAt: new Date(),
    subject: await User.findById(userId).select("-passwordHash"),
    orders: await Order.find({ userId }),
    comments: await Comment.find({ userId }),
    loginHistory: await LoginHistory.find({ userId }),
    consentRecords: await Consent.find({ userId }),
    dataProcessingActivities: getProcessingActivities(userId),
    thirdPartySharing: await getThirdPartyShareLog(userId),
    retentionPolicy: getRetentionPolicyForUser(userId),
  };

  return report; // Deliver in machine-readable format (JSON, CSV)
}

Privacy Engineering Checklist

  • Data inventory: Document every piece of personal data collected
  • Purpose limitation: Each data point has a documented processing purpose
  • Consent mechanism: Users can grant/withdraw consent granularly
  • DSAR endpoint: Users can download all their data
  • Deletion endpoint: Users can request full data deletion
  • Data retention: Automated deletion after retention period
  • Encryption: PII encrypted at rest and in transit
  • Access controls: Minimum employees can access PII
  • Audit logging: All PII access is logged
  • Breach response: Automated breach detection and notification
  • Third-party DPAs: Data Processing Agreements with all vendors
  • Privacy Impact Assessment: DPIA for high-risk processing

Further Reading

Advertisement