Engineering Case Study
First-Party Architecture

How We Built Mystery Messages

Mystery Messages is built from the ground up as a high-performance, real-time anonymous feedback platform. This case study details our framework choices, database schema design, security architecture, serverless backend constraints, and engineering lessons learned.

1. Core Technology Stack

Our codebase is structured around modern React and Next.js serverless primitives:

Frontend & Framework

• Framework: Next.js 15 App Router

• UI Components: React 19, Tailwind CSS, shadcn/ui

• Icons & Motion: Lucide Icons, Framer Motion

• Build Tooling: Bun runtime

Backend & Infrastructure

• Database: MongoDB Atlas cloud database

• Authentication: Secure Session Auth (Credentials, Google, Facebook)

• Encryption: Symmetric AES-256 message encryption

• Push Notifications: Asynchronous Expo Push delivery

2. Database Architecture & Embedded Document Design

Rather than separating user accounts and messages into standalone relational tables, Mystery Messages utilizes an embedded document pattern in MongoDB for optimal read performance:

High-Level MongoDB Document Concept

// High-level User & Message Document Structure
{
  username: "johndoe",
  email: "john@example.com",
  subscriptionTier: "FREE" | "PRO" | "PRO_MAX",
  platform: "web" | "android_app" | "windows_app",
  messages: [
    {
      content: "[AES-256 Encrypted Ciphertext]",
      createdAt: ISODate("2026-10-03T00:00:00Z"),
      sentimentScore: 85,
      isLocked: false,
      senderMetadata: { /* Anonymized network & device markers */ }
    }
  ]
}

3. Authentication Architecture & Platform Attribution

Authentication uses encrypted session tokens with custom platform context:

  • OAuth Platform Attribution: Sign-ups from web, Android app, or Windows PWA append a deliberate platform tag (web, android_app, windows_app) stored in MongoDB to track platform adoption accurately.
  • One-Time Desktop Onboarding: Desktop and Microsoft Store users undergo a one-time onboarding flow stored in local state, preventing repetitive onboarding prompts.

4. Server Boundary & Message Visibility Architecture

One of our core architectural challenges was enforcing the 30-message free visibility rule securely without rejecting incoming sender messages:

Server API Sanitization Pipeline

In our message retrieval endpoint, chronological messages 31+ are checked against user subscription and individual unlock flags. For locked messages on free tier, the API returns safe metadata only:

// Server-side boundary output for locked 31+ messages (FREE Tier):
{
  "_id": "66f123456789...",
  "createdAt": "2026-10-03T00:00:00Z",
  "isLocked": true
  // Note: 'content' and ciphertext are omitted entirely from server response
}

This guarantees that client-side DOM inspection or browser network monitoring cannot reveal private message content for locked notes on free accounts.

5. Engineering Lessons Learned & Challenges

Serverless Connection Pooling

In Next.js serverless API routes, creating new database connections per request causes pool exhaustion. We implemented cached connection state to reuse MongoDB handles across function invocations.

Async Non-Blocking Push Dispatch

Dispatching push notifications synchronously delayed message delivery responses. We refactored push token dispatch into an un-awaited background task with notification rate-limiting.

Try Mystery Messages Today

Experience our fast, secure, and modern anonymous message platform firsthand.