Frontend School

Designing a High-Performance Threaded Email Viewer for Meesho's Internal Tools

System Design
hard

Designing a High-Performance Threaded Email Viewer for Meesho's Internal Tools

Hard
Email Client
Threading
Frontend System Design
Performance
Scalability
Real-time Updates
State Management
UI Architecture

Overview

Meesho's customer support and seller management teams rely heavily on internal tools for communication. A critical component is an email client that allows agents to efficiently manage conversations with customers and sellers. This problem focuses on designing the client-side architecture for a highly performant and scalable threaded email viewer, enabling agents to quickly navigate and respond to complex communication histories.

What you need to do / Task

You are tasked with designing the frontend system for rendering email conversations in a threaded view. Your design should demonstrate an understanding of efficient data retrieval, client-side state management, UI rendering performance for deep threads, and handling real-time updates in a multi-user environment.

Scenario

Imagine a Meesho customer support agent using an internal email client. When they click on an email in their inbox, they expect to see the full conversation thread associated with that email. This thread can be shallow (2-3 emails) or very deep (20-50+ emails), potentially spanning days or weeks. The agent needs to quickly scroll through the thread, identify new messages, and interact with individual emails (e.g., mark as read, reply). The system must feel responsive even when dealing with thousands of emails across hundreds of active threads.

Constraints

Constraints & assumptions

  • User Base: 5,000+ concurrent agents accessing the email client.
  • Email Volume: Each agent might have thousands of emails in their inbox, with hundreds of active threads.
  • Thread Depth: Threads can contain anywhere from 2 to 50+ emails. Average thread depth is 8-10 emails.
  • Data Source: Assume a robust backend API that can provide email data, including a threadId for grouping. The backend handles the core threading logic.
  • Performance Targets:
    • Initial load of a thread (up to 20 emails): < 500ms.
    • Scrolling performance: Smooth 60fps even with deep threads.
    • Real-time updates: New emails appearing in an open thread should be visible within 2 seconds.
  • Environment: Modern web browser (Chrome, Firefox, Edge), JavaScript/TypeScript, React/Vue/Angular (candidate's choice).
  • Client-side Memory: Keep memory footprint reasonable to avoid browser slowdowns, especially for agents who keep the client open for extended periods.

Out of scope

  • Backend threading logic (assume threadId is provided).
  • Sending emails, composing new emails, rich text editor.
  • Attachment handling.
  • Advanced search and filtering capabilities.
  • Full-text indexing.
  • Authentication and Authorization.

What interviewers evaluate

  • Architectural Design: How well the system is structured for maintainability, performance, and scalability.
  • Performance Optimization: Strategies employed to achieve smooth rendering and quick load times for complex threads.
  • Data Management: Efficient handling of email data, including caching, state management, and real-time updates.
  • API Interaction: Thoughtful design of client-server communication for fetching and updating data.

Requirements

1.

Design a client-side data model that efficiently represents email threads, allowing for quick traversal and hierarchical rendering.

2.

Propose a component architecture for the thread viewer that supports rendering of individual emails, nested replies, and expand/collapse functionality.

3.

Detail strategies for optimizing initial thread load time and ensuring smooth scrolling performance for threads containing 50+ emails.

4.

Outline a robust state management approach for handling thread data, individual email states (read/unread, expanded/collapsed), and ensuring UI consistency.

5.

Describe how real-time updates from the WebSocket/SSE are consumed and integrated into the active thread view without full page refreshes.

6.

Explain how the system handles potential memory constraints and ensures a reasonable client-side memory footprint, especially for long-running sessions.

7.

Discuss considerations for handling concurrency issues if multiple agents could potentially interact with the same thread (e.g., marking an email as read).

Design Brief

Detailed Design Brief: Threaded Email Viewer

You are tasked with designing the client-side architecture for a high-performance threaded email viewer for Meesho's internal agent tools. The primary goal is to provide a seamless and responsive experience for agents interacting with email conversations, which are often deep and rapidly evolving.

Core Functionality

When an agent selects an email from their inbox list, the system should display the entire conversation thread associated with that email. The thread view needs to:

  1. Render emails hierarchically: Visually represent the "reply-to" structure, showing nested replies.
  2. Efficiently load and display: Handle threads with many emails (50+) without performance degradation.
  3. Support user interaction: Allow expanding/collapsing individual emails or sub-threads, marking emails as read/unread.
  4. Handle real-time updates: New emails arriving in an actively viewed thread should appear instantly without a full page refresh.

API Assumptions

Assume the following backend API endpoints are available:

  • GET /api/threads/{threadId}: Returns a list of emails belonging to a specific threadId.
    • Response example:
      {
        "threadId": "thread_abc_123",
        "emails": [
          {
            "id": "email_001",
            "threadId": "thread_abc_123",
            "sender": "customer@example.com",
            "recipient": "agent@meesho.com",
            "subject": "Order #12345 Issue",
            "bodyPreview": "Hi, my order...",
            "timestamp": "2023-10-26T10:00:00Z",
            "isRead": true,
            "inReplyTo": null, // For the first email in a thread
            "references": [] // For email clients to determine threading, backend uses this to derive threadId
          },
          {
            "id": "email_002",
            "threadId": "thread_abc_123",
            "sender": "agent@meesho.com",
            "recipient": "customer@example.com",
            "subject": "Re: Order #12345 Issue",
            "bodyPreview": "Hello, I understand...",
            "timestamp": "2023-10-26T10:15:00Z",
            "isRead": true,
            "inReplyTo": "email_001", // ID of the email this is a reply to
            "references": ["email_001"]
          }
          // ... more emails
        ]
      }
      
  • GET /api/inbox?agentId={agentId}&page={page}&limit={limit}: Returns a paginated list of top-level emails (or thread summaries) for the inbox view.
  • POST /api/emails/{emailId}/markAsRead: Marks an email as read.
  • POST /api/emails/{emailId}/markAsUnread: Marks an email as unread.
  • Real-time updates: Assume a WebSocket or Server-Sent Events (SSE) connection is available at /ws/agent/{agentId} that pushes notifications for new emails or updates to existing emails relevant to the agent.
    • Payload example:
      {
        "type": "NEW_EMAIL",
        "email": { /* full email object, including threadId */ }
      }
      
      or
      {
        "type": "EMAIL_UPDATED",
        "emailId": "email_001",
        "updates": { "isRead": false }
      }
      

Design Considerations

Your design should address the following:

  1. Client-side Data Structure: How will you store and manage email and thread data in the browser's memory for efficient access and rendering? Consider the hierarchical nature of threads.
  2. Component Hierarchy: Outline the main UI components (e.g., ThreadView, EmailItem, EmailBody) and their responsibilities.
  3. Performance Optimization:
    • Initial Load: Strategies to quickly display the thread, especially for deep conversations.
    • Scrolling: Techniques to maintain smooth scrolling (e.g., virtualization, lazy loading).
    • Re-renders: Minimizing unnecessary UI updates.
  4. State Management: How will you manage the state of open threads, individual email read/unread status, expanded/collapsed states, etc.? Consider global vs. local state.
  5. Real-time Updates: How will you integrate WebSocket/SSE notifications to update the UI without requiring a full data refetch for the entire thread?
  6. Error Handling & Fallbacks: Briefly describe how you would handle API errors or network disconnections.
  7. Scalability: How would your design accommodate a future where threads become even deeper (e.g., 100+ emails) or the number of concurrent users significantly increases?

Be prepared to draw diagrams (e.g., component hierarchy, data flow, sequence diagrams for real-time updates) using Excalidraw to illustrate your design. Discuss trade-offs for different approaches.

Loading editor...