Are you preparing for a senior developer interview that focuses on Gatsby.js? This guide walks through 30 essential questions, with interviewer-friendly answers that reflect deep technical understanding. Whether you're brushing up or aiming to stand out, this list will help you articulate your knowledge clearly and confidently.
Core Concepts
1. Explain Gatsby's architecture and how it differs from traditional React apps
Gatsby is a static site generator that uses React for UI, GraphQL for data, and Webpack for bundling. Unlike traditional React apps, which fetch data at runtime, Gatsby fetches and compiles data at build time, generating static HTML for each page. This results in better performance, SEO, and reduced reliance on server infrastructure.
2. How does Gatsby's data layer work with GraphQL?
Gatsby creates a centralized GraphQL layer from multiple data sources like Markdown, CMSs (e.g., Contentful, WordPress), APIs, or local files. During the build, GraphQL queries embedded in components are executed, and their results are injected into pages as static props, allowing for a seamless, decoupled content integration.
3. What are Gatsby's key performance optimizations?
- Static rendering: Pages are pre-built for fast load times.
-
Image optimization: Uses
gatsby-plugin-image
to serve responsive, lazy-loaded images. - Code splitting: Only required JS is loaded per page.
- Prefetching: Links are preloaded in the background.
- Tree shaking: Removes unused code during bundling.
4. Explain Gatsby's build process step-by-step
- Bootstrap phase: Loads config and plugins.
- Source nodes: Fetches data from all plugins (CMS, Markdown, etc.).
- Create GraphQL schema: Based on sourced data.
- Run GraphQL queries: Component and page queries are executed.
- Page generation: HTML and static assets are created using React and Webpack.
- Bundle: Final assets are optimized and emitted.
5. How does Gatsby handle routing differently from traditional React apps?
Gatsby uses file-based routing, where each file in src/pages/
automatically becomes a route. There's no need for a manual route configuration like react-router
. For dynamic pages, the createPages
API in gatsby-node.js
programmatically generates routes.
Data Handling
6. Compare sourcing data from Markdown vs CMS in Gatsby
-
Markdown is ideal for small to medium sites. It’s local, fast, and simple to manage using tools like
gatsby-transformer-remark
. - Headless CMSs (e.g., Contentful, Strapi) are suited for dynamic or content-heavy sites with non-technical editors. They allow real-time content updates and scalability.
7. How would you implement incremental builds in Gatsby?
Gatsby Cloud and Netlify support Incremental Builds, where only changed content triggers rebuilds. This is enabled by tracking file/dataset changes and only regenerating affected pages, significantly speeding up deployment times for large sites.
8. Explain Gatsby's image optimization approach
Gatsby processes images during build using gatsby-plugin-sharp
and gatsby-plugin-image
, generating multiple resolutions and formats (like WebP). It automatically adds loading="lazy"
and srcSet
for responsive loading, which boosts both performance and Core Web Vitals.
9. How do you handle dynamic content in a static Gatsby site?
Use client-only routes (/src/pages/app/*.js
), or client-side rendering via useEffect()
to fetch data after the page loads. Gatsby also supports Deferred Static Generation (DSG) and Server-Side Rendering (SSR) for partially dynamic use cases.
10. What strategies would you use for large-scale Gatsby sites with thousands of pages?
- Use
createPages
with pagination. - Implement programmatic lazy creation of pages.
- Cache GraphQL results.
- Use Gatsby’s incremental build support.
- Optimize image and data transformations.
Performance
11. How would you optimize a Gatsby site loading time from 5s to under 1s?
- Optimize image formats and dimensions.
- Minimize GraphQL query payloads.
- Use
gatsby-plugin-preload-fonts
. - Remove unused CSS/JS.
- Implement lazy loading for components and media.
- Compress assets with Brotli or Gzip.
12. Explain how to implement code splitting in Gatsby
Gatsby performs route-based code splitting by default. For finer control, use React.lazy()
and Suspense
to split non-critical or large components and load them asynchronously.
13. How does Gatsby's hydration process work?
Once static HTML is served to the client, Gatsby re-renders React components on the client-side and binds event listeners—this is called hydration, and it ensures interactivity while preserving fast initial load times.
14. What techniques would you use to reduce bundle size in Gatsby?
- Remove unused dependencies and polyfills.
- Use
lodash-es
ordate-fns
instead of large utility libraries. - Enable tree-shaking.
- Use smaller, modular libraries.
- Analyze bundles with
webpack-bundle-analyzer
.
15. How would you implement lazy loading for components in Gatsby?
Wrap components with React.lazy()
and Suspense
, or dynamically import them inside useEffect()
for non-critical UI. Gatsby’s built-in support also helps lazy load images and iframes.
Plugins & Themes
16. How would you create a custom Gatsby plugin?
Create a new directory inside /plugins
, add gatsby-node.js
, and export Node APIs (e.g., onCreateNode
, createPages
). Define plugin metadata in package.json
, and optionally expose configuration options.
17. Explain Gatsby theme composition and shadowing
Gatsby themes are reusable site packages. Theme composition allows stacking multiple themes, and shadowing lets you override files from a theme by replicating the file path in the main project.
18. How would you modify a Gatsby starter to fit specific needs?
- Remove unnecessary plugins/components.
- Customize
gatsby-config.js
. - Add new pages or templates.
- Update GraphQL queries to reflect real data structure.
- Add PWA support or custom styling as needed.
19. What's your process for evaluating Gatsby plugins?
- Check GitHub stars, issues, and last commit.
- Review community adoption and docs.
- Ensure compatibility with current Gatsby version.
- Evaluate plugin size, performance, and configuration needs.
20. How would you implement a multi-language Gatsby site?
Use gatsby-plugin-react-i18next
or gatsby-plugin-intl
, create content in locale folders, use language-specific routing, and dynamically query localized content using GraphQL variables.
Advanced Patterns
21. How would you implement A/B testing in Gatsby?
Use client-side rendering to load different components based on user segments or random splits. You can also integrate tools like Google Optimize or use custom logic with local storage or cookies.
22. Explain how to handle authentication in Gatsby
Use client-only routes for protected pages. Integrate auth providers like Firebase, Auth0, or Cognito. Store tokens securely in memory or cookies, and manage access using higher-order components or context.
23. How would you implement a search functionality in Gatsby?
-
Static search: Use
Lunr.js
orFuse.js
to index content at build time. -
Dynamic search: Use Algolia with
gatsby-plugin-algolia
to sync content and perform real-time queries on the frontend.
24. What strategies would you use for GDPR compliance in Gatsby?
- Use a cookie consent banner.
- Defer tracking scripts until consent is given.
- Avoid collecting personal data unless necessary.
- Anonymize IPs in analytics and comply with data deletion requests.
25. How would you implement a headless e-commerce site with Gatsby?
Use a headless commerce API (e.g., Shopify, Snipcart). Fetch product data via GraphQL or REST, create product pages with createPages
, and manage cart and checkout with client-side logic or APIs.
Deployment & CI/CD
26. How would you set up a CI/CD pipeline for Gatsby?
Use GitHub Actions, GitLab CI, or Netlify/Gatsby Cloud:
- Trigger builds on commit or PR.
- Lint and test code.
- Run Gatsby build.
- Deploy to CDN or static host.
27. Explain your approach to monitoring a Gatsby site in production
Use tools like Sentry for error tracking, Google Analytics for usage insights, and Lighthouse CI to track performance metrics. Gatsby Cloud also provides build logs and error insights.
28. How would you handle rollbacks for a Gatsby site?
Use deployment platforms like Netlify or Vercel that support previous build snapshots. Roll back by redeploying a previous commit or switching to a known stable version.
29. What's your strategy for implementing preview environments?
Deploy preview branches using Netlify/Gatsby Cloud. Connect with your CMS’s preview mode, allowing content editors to see unpublished changes in real-time before going live.
30. How would you migrate a legacy site to Gatsby?
- Audit and plan content structure.
- Choose a suitable data source (CMS or local).
- Rebuild UI components using React.
- Migrate SEO, metadata, and URLs.
- Implement redirects and test thoroughly before launch.
Final Thoughts
Gatsby combines the best of React, static site generation, and modern performance techniques. As a senior developer, showing that you can work efficiently with its data layer, performance tools, and ecosystem integrations will set you apart. These answers strike the balance between clarity and depth—exactly what interviewers look for.
Good luck, and go build something blazing fast!