KatInterview

Secure S3 Upload Patterns and TypeScript Structural Typing

System DesignModel answer

Last updated

Architect secure, direct S3 uploads via pre-signed URLs/IAM and analyze TypeScript structural typing alongside React useEffect async cleanup.

This technical screen assesses two core software engineering domain areas: cloud security architecture on AWS and frontend engineering using React with TypeScript.


Section A: Cloud Storage & Security Architecture

Your web application needs to allow users to upload files directly from their browsers into an Amazon S3 bucket.

  1. Architecture & Flow: Design a secure, direct-to-S3 upload process. Explain how to achieve this without embedding long-lived AWS credentials in the frontend and without making the target S3 bucket publicly accessible.
  2. IAM Configuration: Detail the exact IAM policy principles and permissions you must grant to your backend server to enable this pattern safely.
  3. Data Integrity & Enforcement: Explain how to restrict key names, payload sizes, and media types so that malicious actors cannot upload unauthorized data or overwrite existing files.

Section B: Type Systems & React State Lifecycle

Examine the following TypeScript and React code snippet:

interface UserProfile {
  id: string;
  email: string;
  isAdmin: boolean;
}

function UserCard({ user }: { user: UserProfile }) {
  // Note: assume standard JSX rendering
  return <div>{user.email}</div>;
}
  1. Structural vs. Nominal Typing: Contrast TypeScript's structural type system with nominal type systems found in languages such as Java or C#. How does structural typing affect what arguments can be validly passed into UserCard? Explain the concept of excess property checking.
  2. Asynchronous Effects & Memory Management: When fetching data inside a React useEffect hook to populate a component like UserCard, what bugs or edge cases (e.g., race conditions, unmounted state updates) can occur? Provide a code sample showing how to correctly handle component unmounting and fetch cancellation.

Hints

Hint 1

Consider AWS pre-signed URLs or pre-signed POST policies to delegate short-lived upload authority.

Hint 2

Ensure the application server uses temporary role-based credentials (STS) through IAM roles for compute instances rather than hardcoded access keys.

Hint 3

Think about how TypeScript checks types on direct object literals versus assigned variables (excess property checking).

Hint 4

Use AbortController inside the React useEffect cleanup function to prevent race conditions and unmounted state updates.