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
80

Frontend System Design · Lesson 80 of 86 · 4 min

Rendering Large Datasets: Canvas vs SVG

This is a classic system design question to gauge your understanding of browser rendering trade-offs.

When you need to render thousands of data points, a naive approach of creating one DOM element per point will cripple your application. The browser's rendering engine wasn't built for that. You have two main strategies: either drastically reduce the number of DOM nodes you render at any given time, or avoid creating them for each data point altogether.

For long lists and tables, the first strategy is virtualization. You only render the items currently in the viewport (plus a small buffer), creating the illusion of a complete list by manipulating scroll height and offsets.

For data visualizations, the choice is more fundamental: do you use a DOM-based approach (SVG) or a pixel-based one (Canvas)? This decision dictates performance, interactivity, and accessibility from the start.

SVG: The DOM-based, Interactive Choice

SVG (Scalable Vector Graphics) is a retained-mode graphics system. Every circle, path, and text element you create is a distinct DOM node. You can inspect it in the dev tools, style it with CSS, and attach event listeners directly to it.

This makes it ideal for standard charts and diagrams where interactivity is key. Think of a bar chart where you need to show a tooltip on hover for each bar. With SVG, it's just a mouseover event on a <rect> element. It's also resolution-independent and inherently more accessible.

In an interview, explain that most chart libraries like D3 default to SVG for a reason: it maps cleanly to familiar web development patterns (DOM manipulation, events, CSS) and is perfect for visualizations with hundreds, or even a couple thousand, elements.

The problem is the DOM overhead. Performance falls off a cliff as the number of nodes increases. Once you get into the high thousands of elements, the browser will struggle with layout, styling, and event handling.

Canvas: The High-Performance Pixel Buffer

Canvas is an immediate-mode graphics system. You get a single <canvas> DOM element, which is a blank, raster bitmap. You use a JavaScript API to draw pixels onto it. Once drawn, the browser forgets about the "circle" or "line"; it only knows about the resulting pixels.

This "fire and forget" model is incredibly fast. You can render hundreds of thousands of shapes without the browser breaking a sweat, because you're not creating thousands of DOM nodes. This is your tool for high-density scatter plots, heatmaps, or real-time graphs with constant updates.

The trade-offs are significant. Interactivity is manual; if you want to know if the user clicked a circle, you must write hit-detection logic that maps mouse coordinates to the shapes you've drawn. Accessibility is also manual; a screen reader sees a single image, so you must provide fallbacks or use parallel DOM structures.

The trap: Candidates often forget about high-DPI screens. A canvas will look blurry on a Retina display unless you account for window.devicePixelRatio. You must scale the canvas dimensions and the drawing context. Forgetting this detail shows a lack of production experience.

const dpr = window.devicePixelRatio || 1;
const rect = canvas.getBoundingClientRect();

// Set the canvas size in CSS pixels, then scale its backing store.
canvas.width = rect.width * dpr;
canvas.height = rect.height * dpr;

// Scale the context to ensure drawings are not stretched.
const ctx = canvas.getContext('2d');
ctx.scale(dpr, dpr);

// Now your drawings will be crisp.
ctx.fillRect(10, 10, 100, 100);

How to Choose: The Decision Framework

Your choice depends on the intersection of element count and interactivity needs. There is no single "better" option, only the right tool for the job.

Use this decision flow to structure your answer.

Start your interview answer by framing the problem this way. "First, I'd clarify the requirements. How many data points are we talking about? Do we need to interact with individual points, or just the chart as a whole? Is accessibility a primary concern?"

This shows you understand the core trade-offs before jumping to a solution. For a scatter plot with 50,000 points, say Canvas. For an interactive dashboard with 20 distinct, clickable charts, say SVG. For a hybrid, mention layering a transparent SVG for UI elements (like tooltips or selection boxes) over a Canvas for the dense data.

Show the Difference: Imperative vs. Declarative Code

The programming model is fundamentally different. SVG is declarative: you describe what you want, and the browser builds a DOM tree. Canvas is imperative: you give the browser step-by-step instructions on how to draw.

Here's how you'd draw 1,000 random circles with each.

SVG (Declarative): You generate an array of data, and your view layer (e.g., React, Svelte) maps it to SVG elements. The result is a large DOM fragment.

// Assuming a framework that renders this array into SVG
function createSvgCircles(count) {
  const circles = [];
  for (let i = 0; i < count; i++) {
    circles.push({
      cx: Math.random() * 300,
      cy: Math.random() * 300,
      r: 2,
      fill: 'blue',
    });
  }
  // In React: return circles.map(c => <circle {...c} />);
  // In vanilla JS: return circles.map(c => `<circle cx="${c.cx}" ... />`).join('');
  return circles;
}

Canvas (Imperative): You get a drawing context and issue a series of commands inside a loop. Nothing is added to the DOM.

function drawCanvasCircles(canvas, count) {
  const ctx = canvas.getContext('2d');
  ctx.clearRect(0, 0, canvas.width, canvas.height); // Clear canvas
  ctx.fillStyle = 'blue';

  for (let i = 0; i < count; i++) {
    const cx = Math.random() * canvas.width;
    const cy = Math.random() * canvas.height;
    ctx.beginPath();
    ctx.arc(cx, cy, 2, 0, 2 * Math.PI);
    ctx.fill();
  }
}

The Canvas code is often more verbose but avoids the performance cost of DOM manipulation for every single shape.

Try it

Open a CodePen or local file. Render 5,000 small circles using both SVG and Canvas. Use requestAnimationFrame to slightly change their position on each frame. Observe the difference in frame rate using your browser's performance profiler.

Next: We'll build on this by making our visualizations interactive and responsive in the lesson on Interactive, Responsive Data Visualizations.

Lock it in — apply this lesson under interview conditions.

Try a free mock interviewPractice system design problems
Previous

Choosing a Chart Library: D3, Chart.js, Recharts

Next

Interactive, Responsive Data Visualizations