frontend-interview-questions

1. How do you design a CI/CD pipeline for a React application to ensure fast feedback loops and reliable deployments?

# GitHub Actions sample
jobs:
  build-test:
    steps:
      - run: npm ci
      - run: npm run lint && npm test
  deploy:
    steps:
      - run: npm run build
      - run: npm run deploy:staging


2. What’s your approach to automating the deployment of a React app to multiple environments (e.g., dev, staging, prod)?


if [ "$ENV" == "staging" ]; then
  npm run deploy:staging
fi


3. How do you integrate automated testing (unit, integration, E2E) into a CI/CD pipeline for a React project?

steps:
  - run: npm test -- --coverage
  - run: npx cypress run


4. What’s your strategy for handling rollbacks in a CI/CD pipeline when a deployment fails in production?


aws s3 cp s3://backups/last-good-build ./ && npm run deploy


5. How do you optimize a CI/CD pipeline to reduce build times for a large React codebase?

- uses: actions/cache@v3
  with:
    path: node_modules


6. What’s your approach to securing a CI/CD pipeline for a React application?


7. How do you implement blue-green or canary deployments in a CI/CD pipeline for a React app?


if (user.isInCanaryGroup) {
  return <NewComponent />
}


8. What’s your process for integrating static code analysis and linting into a CI/CD pipeline?

- run: npm run lint && npm run type-check


9. How do you handle dependency management and versioning in a CI/CD pipeline for a React project?


10. How do you educate a team on adopting and maintaining a CI/CD pipeline for a React application?


11. How do you design a monitoring system for a React application in production to track performance and errors?


12. What’s your approach to monitoring Core Web Vitals (e.g., LCP, CLS, FID) in a React app post-deployment?


import { onCLS, onFID, onLCP } from 'web-vitals';
onCLS(sendToAnalytics); onLCP(sendToAnalytics); onFID(sendToAnalytics);


13. How do you set up real-time alerts for a React application to catch runtime errors or performance degradation?


14. What’s your strategy for monitoring API latency and availability in a React app that relies on a backend?


const start = performance.now();
fetch('/api/data').finally(() => {
  const duration = performance.now() - start;
  if (duration > 1000) logSlowAPI('/api/data', duration);
});


15. How do you use monitoring tools to track the health of a CI/CD pipeline itself (e.g., build success rates, deployment times)?


16. What’s your approach to logging in a React application, and how do you integrate it with monitoring tools?

export const log = (msg) => {
  if (process.env.NODE_ENV === "production") {
    sendToLoggingService(msg);
  } else {
    console.log(msg);
  }
};


17. How do you implement distributed tracing in a React app with a microservices backend?

fetch("/api", {
  headers: { "x-trace-id": currentTraceId },
});


18. What’s your process for monitoring resource usage (e.g., CPU, memory) in a React app deployed on a serverless platform?


if (performance.memory) {
  log(performance.memory.usedJSHeapSize);
}


19. How do you leverage monitoring tools to support A/B testing or feature flag rollouts in a React app?

analytics.track("feature_used", { variant: "B" });


20. How do you train a team to use monitoring tools effectively for a React application in production?