📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

Your ASP.NET Core app works with one replica, but after scaling to three, users are randomly logged out and antiforgery validation fails. What is wrong?

Junior Theory Beginner

🎯 Key points

  • Each instance generates its own Data Protection key ring by default
  • Cookies and antiforgery tokens from one replica cannot be decrypted by another
  • PersistKeysToAzureBlobStorage for a shared key ring
  • ProtectKeysWithAzureKeyVault to encrypt keys at rest
  • Same SetApplicationName on every instance
  • Session via IDistributedCache (Redis), not in-memory
  • Sticky sessions are only a stopgap: fail on deploys, scale-in and rescheduling

⏱ 30-second answer

ASP.NET Core's Data Protection system encrypts auth cookies and antiforgery tokens with a key ring. By default each instance creates its own key ring on local disk, so a cookie protected by replica A cannot be decrypted by replica B, and every redeploy creates new keys. Fix it by persisting keys to a shared store (PersistKeysToAzureBlobStorage), protecting them at rest with Key Vault (ProtectKeysWithAzureKeyVault) and setting the same SetApplicationName on every instance. If the app uses session, back it with IDistributedCache (Redis) so any replica can read it. Sticky sessions only hide the problem: they break on scale-in, deploys and pod rescheduling, so treat them as a stopgap, not the fix.

🔍 What the interviewer is checking

Checks they know Data Protection keys and session are hidden state.

↩ Usually asked after

More in Cloud-Native Patterns

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me