Frontend School
DashboardProblemsLearnPracticeMock InterviewReportsStatsBuy Credits
DashboardProblemsLearnPracticeMock Interview
Frontend System Design Roadmap
  1. 1.HTTP/1.1 vs HTTP/2 vs HTTP/3 (QUIC)
  2. 2.TCP and TLS Handshakes: Connection Setup Costs
  3. 3.Browser Network Stack and Connection Pooling
  4. 4.GET vs POST and Idempotency in HTTP
  5. 5.The Critical Rendering Path (CRP)
  6. 6.DOM, CSSOM and the Render Tree
  7. 7.Layout, Paint and Compositing
  8. 8.Reflows and Repaints Explained
  9. 9.Event Loop: Call Stack, Task and Microtask Queues
  10. 10.Async JavaScript: Promises and async/await
  11. 11.Web Workers: Multi-threading in the Browser
  12. 12.Browser Storage: Cookies, Web Storage, IndexedDB
  13. 13.Client-Side Storage: Limits and Security Risks
  14. 14.Choosing the Right Client-Side Storage
  15. 15.HTTP Caching: Cache-Control, ETag, Last-Modified
  16. 16.Browser-Level Caching Mechanisms
  17. 17.Cache Invalidation for Frontend Apps
  18. 18.Structuring a Large Single-Page App
  19. 19.Component-Based Architecture Principles
  20. 20.Props, State and Component Lifecycle
  21. 21.Module Bundling Basics
  22. 22.Core Web Vitals: LCP, INP and CLS
  23. 23.FCP and Time to Interactive (TTI) Explained
  24. 24.Measuring Performance: Lighthouse and WebPageTest
  25. 25.Asset Compression and Minification Basics
  26. 26.What Is a CDN and How Does It Work?
  27. 27.CDN Benefits: Latency, Availability, Offload
  28. 28.CDN Cache Behavior and Invalidation
  29. 29.Global State vs Local Component State
  30. 30.State Patterns: Redux, Zustand and Context
  31. 31.Data Fetching: React Query and SWR
  32. 32.Immutable Data in Frontend State
  33. 33.SSR vs CSR: Rendering Trade-offs
  34. 34.Hydration and Time to First Byte (TTFB)
  35. 35.Static Site Generation (SSG) for Speed and SEO
  36. 36.Incremental Static Regeneration (ISR)
  37. 37.Micro-Frontends: Core Principles
  38. 38.Micro-Frontend Integration Strategies
  39. 39.Communication Between Micro-Frontends
  40. 40.Micro-Frontends: Pros and Cons for Large Teams
  41. 41.Real-Time: Polling, SSE and WebSockets
  42. 42.Real-Time Use Cases: Chat, Alerts, Live Data
  43. 43.Designing a Real-Time Data Flow
  44. 44.Scaling WebSocket Connections
  45. 45.Responsive Images: srcset, sizes and picture
  46. 46.Modern Image Formats: WebP, AVIF, JPEG XL
  47. 47.Lazy Loading Images and Videos
  48. 48.Video Streaming: HLS, DASH, Adaptive Bitrate
  49. 49.REST and GraphQL for Frontend Engineers
  50. 50.Batching, Throttling and Debouncing API Calls
  51. 51.Handling API Errors in the Frontend
  52. 52.Authentication Flows: OAuth and JWT
  53. 53.Global Error Boundaries in React
  54. 54.Error Reporting: Sentry and LogRocket
  55. 55.Graceful Degradation and Fallback UIs
  56. 56.Real User Monitoring (RUM)
  57. 57.CORS: Cross-Origin Resource Sharing
  58. 58.Preventing XSS (Cross-Site Scripting)
  59. 59.CSRF Protection for Frontend Apps
  60. 60.Content Security Policy (CSP)
  61. 61.Storing Auth Tokens: Cookies vs localStorage
  62. 62.PWA Manifest and Installability
  63. 63.Service Workers: Lifecycle and Caching Strategies
  64. 64.Offline Support and Background Sync
  65. 65.Push Notifications for Web Apps
  66. 66.Webpack vs Vite vs Parcel
  67. 67.Code Splitting, Tree Shaking, Asset Optimization
  68. 68.Module Resolution and Hot Module Replacement
  69. 69.Monorepo Tooling: Nx and Lerna
  70. 70.Atomic Design for Component Libraries
  71. 71.Theming and Customization in Design Systems
  72. 72.Accessibility in Component Libraries
  73. 73.Component Library Docs, Testing and Versioning
  74. 74.Publishing and Consuming a Component Library
  75. 75.Full-Text Search: Levenshtein and Fuzzy Matching
  76. 76.Indexing Large Datasets in the Browser
  77. 77.Search Performance: Debouncing and Web Workers
  78. 78.Integrating Backend Search Services
  79. 79.Choosing a Chart Library: D3, Chart.js, Recharts
  80. 80.Rendering Large Datasets: Canvas vs SVG
  81. 81.Interactive, Responsive Data Visualizations
  82. 82.Data Fetching and Aggregation for Dashboards
  83. 83.A/B Test Design and Rollout Strategies
  84. 84.Client-Side vs Server-Side A/B Testing
  85. 85.Feature Flags and Remote Configuration
  86. 86.Experiment Data Collection and Analytics
Frontend System Design Roadmap
74

Frontend System Design · Lesson 74 of 86 · 5 min

Publishing and Consuming a Component Library

This is a classic system design question that tests your grasp of the entire frontend ecosystem, from build tools to dependency management.

After this, you'll be able to explain the end-to-end lifecycle of a component library package. You'll know what to configure, what to build, and how to answer the inevitable follow-up questions about bundle size, versioning, and breaking changes.

The Core Problem: Distributing Code, Not Just Components

You aren't just shipping a folder of React components. You are shipping a dependency that must work reliably in dozens of different consumer environments: Next.js, Vite, Create React App, etc. Each has its own build system, module resolution strategy, and dependencies.

Your job is to package your library into a standard, predictable format. This means providing:

  1. JavaScript Bundles: At least two formats. CommonJS (CJS) for older tooling and Node.js environments, and ES Modules (ESM) for modern bundlers that can perform tree-shaking.
  2. Type Definitions: A single .d.ts file that provides TypeScript support for your entire library. This is non-negotiable for a modern library.
  3. CSS: A compiled CSS file or a mechanism for CSS-in-JS to work without conflicts.

Everything else—source code, tests, docs—should be kept out of the final package to keep it small.

Configuring package.json for Consumption

The package.json is the manifest that tells package managers and bundlers how to use your library. Get this wrong, and your library is either broken or inefficient.

These are the fields that matter most:

  • "main": The entry point for CommonJS. Points to your CJS bundle. Example: "dist/index.js".
  • "module": The entry point for ES Modules. Points to your ESM bundle. Modern bundlers will pick this field to enable tree-shaking. Example: "dist/index.mjs".
  • "types": The entry point for TypeScript type definitions. Points to your bundled .d.ts file. Example: "dist/index.d.ts".
  • "files": An explicit whitelist of files and directories to include in the published package. If you omit this, you might accidentally publish source code, tests, or config files. Always define it.
  • "peerDependencies": Dependencies the consumer must provide. This is for shared, singleton libraries like react or react-dom.
{
  "name": "@my-org/ui-library",
  "version": "1.2.0",
  "main": "dist/cjs/index.js",
  "module": "dist/esm/index.js",
  "types": "dist/index.d.ts",
  "files": [
    "dist"
  ],
  "scripts": {
    "build": "rollup -c",
    "prepublishOnly": "npm run build"
  },
  "peerDependencies": {
    "react": ">=17.0.0",
    "react-dom": ">=17.0.0"
  },
  "devDependencies": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "rollup": "^4.9.0",
    "typescript": "^5.3.3"
  }
}

The trap: Putting react in dependencies instead of peerDependencies. This is a common mistake candidates make. If you do this, a consumer's application can end up with two different versions of React in its bundle. This bloats the bundle and, more importantly, breaks React hooks, which rely on a single, shared instance.

In an interview, confidently state: "React must be a peer dependency. Otherwise, you risk multiple React instances in the application, which leads to invalid hook call errors and unpredictable state."

The Build Pipeline: From Source to Distributable

Your source code (TSX, SCSS) is for development. The distributable code in your dist folder is for consumers. The build pipeline is what bridges that gap.

A typical library build process looks like this:

Rollup is a popular choice for bundling libraries because it excels at creating clean ESM output optimized for tree-shaking. Vite uses Rollup under the hood for its production builds for the same reason. Webpack is also capable but often involves more complex configuration for library output.

The goal is to automate this entire process. The prepublishOnly script in package.json is a lifecycle hook that ensures your build runs right before you publish, preventing you from shipping stale or broken code.

Answering "How do you handle breaking changes?"

This question is a test of your understanding of professional software maintenance. The answer is not just "a major version bump."

The answer is about communication and process, governed by Semantic Versioning (SemVer).

  1. The Contract: SemVer (MAJOR.MINOR.PATCH) is a contract with your consumers. A MAJOR version bump (e.g., 1.5.2 -> 2.0.0) signals breaking changes. A MINOR bump (1.5.2 -> 1.6.0) is for new, backward-compatible features. A PATCH bump (1.5.2 -> 1.5.3) is for backward-compatible bug fixes.

  2. The Process: A breaking change should never be a surprise. A professional rollout involves:

    • Deprecation: Introduce the new API in a MINOR release. Mark the old API as deprecated, logging a console warning that points to the new usage and mentions the future breaking change.
    • Communication: Announce the upcoming breaking change in release notes, documentation, and any relevant communication channels.
    • Migration Guide: For any significant break, write a clear migration guide that shows code examples of what to change.
    • Execution: In the next MAJOR release, remove the deprecated code.

This demonstrates that you think about the impact of your work on other teams, a key senior-level trait.

What Interviewers Are Really Asking

Interview questions about component libraries are proxies for bigger-picture concepts.

  • When they ask about bundle size, they're testing your knowledge of tree-shaking, ESM vs. CJS, peerDependencies, and build tool configuration. They want to know if you can diagnose and solve performance problems.
  • When they ask about theming, they're testing your API design skills. Can you design components that are flexible and extensible? Mentioning CSS Custom Properties or a React Context-based ThemeProvider are good answers.
  • When they ask about monorepos vs. polyrepos, they're evaluating your understanding of architectural trade-offs in dependency management, versioning, and CI/CD complexity. There is no single right answer, so explain the pros and cons of each.
  • When they ask about testing, they want to hear how you guarantee quality before publishing. Mention unit tests for logic (Jest, Vitest), rendering/interaction tests (React Testing Library), and visual regression tests (Storybook, Chromatic).

Try it

Find a small, open-source component library on GitHub (e.g., Radix, Headless UI, or a smaller one). Inspect its package.json and build configuration file (e.g., rollup.config.js or vite.config.ts). Identify its main, module, and types entry points and check its peerDependencies. Can you explain why they made those choices?

Next: Full-Text Search: Levenshtein and Fuzzy Matching.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Component Library Docs, Testing and Versioning

Next

Full-Text Search: Levenshtein and Fuzzy Matching