## Git Version Control Definition: Git is a distributed version control system that tracks changes in source code and enables collaboration among developers. Explanation: Git maintains a history of commits. Key concepts: repository (project), commit (snapshot), branch (parallel line of development), merge (combine branches), rebase (rewrite commit history), and pull request/merge request (code review workflow). Remote repositories (GitHub, GitLab) enable team collaboration. Example: Feature branch workflow — create branch, develop, code review, merge. Code Example: ```bash # Start a new feature git checkout -b feature/user-authentication # Stage and commit changes git add src/auth.js tests/auth.test.js git commit -m "feat: Add JWT-based user authentication - Implement login/logout endpoints - Add token refresh mechanism - Include unit tests" # Update with latest main git fetch origin git rebase origin/main # Push and open PR git push origin feature/user-authentication # After PR is merged, clean up git checkout main git pull origin main git branch -d feature/user-authentication ``` Best Practices: Write clear commit messages (conventional commits format: feat:, fix:, docs:). Use feature branches, never commit directly to main. Rebase to maintain a clean history. Use .gitignore for sensitive files and build artifacts. Common Errors: Committing secrets (API keys, passwords) — use environment variables. Large binary files in Git — use Git LFS. Merge conflicts from not pulling frequently enough. Force-pushing to shared branches. Interview Questions: What is the difference between git merge and git rebase? Explain git stash and when to use it. How do you undo a commit that has already been pushed? ## REST API Design Definition: REST (Representational State Transfer) is an architectural style for building web APIs using HTTP methods and standard conventions. Explanation: REST principles: Stateless (each request is self-contained), Resource-based URLs (nouns not verbs), HTTP methods (GET=read, POST=create, PUT/PATCH=update, DELETE=remove), Standard status codes (200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 500 Server Error), and JSON request/response bodies. Example: Designing a RESTful API for a blog application. Code Example: ``` GET /api/posts → List all posts POST /api/posts → Create a post GET /api/posts/:id → Get a specific post PUT /api/posts/:id → Replace a post PATCH /api/posts/:id → Update part of a post DELETE /api/posts/:id → Delete a post GET /api/posts/:id/comments → Get post's comments // Status codes 201 Created + Location header on POST 204 No Content on successful DELETE 400 Bad Request for invalid input 401 Unauthorized (not logged in) 403 Forbidden (logged in but no permission) 404 Not Found if resource doesn't exist ``` Best Practices: Version your API (/api/v1/). Use plural nouns for resources. Include pagination for list endpoints (limit/offset or cursor). Return consistent error response format. Common Errors: Returning 200 OK for errors. Verbs in URLs (/getUser instead of GET /users/:id). Not validating input — causes security vulnerabilities. Inconsistent naming conventions. Interview Questions: What is the difference between PUT and PATCH? Explain REST vs GraphQL. What is HATEOAS? ## Docker and Containers Definition: Docker is a platform for packaging applications and their dependencies into containers — lightweight, portable, isolated environments that run consistently anywhere. Explanation: A container is a runnable instance of an image. An image is a snapshot built from a Dockerfile. Containers share the host OS kernel (unlike VMs which have separate kernels). Docker Compose manages multi-container apps. Key commands: docker build, docker run, docker push/pull, docker-compose up. Example: Dockerizing a Node.js API for consistent development and production environments. Code Example: ```dockerfile # Dockerfile for Node.js app FROM node:20-alpine # Small base image WORKDIR /app # Layer caching — copy package files first COPY package*.json ./ RUN npm ci --only=production # Install deps COPY . . EXPOSE 3000 # Run as non-root user USER node CMD ["node", "server.js"] ``` ```yaml # docker-compose.yml version: '3.9' services: api: build: . ports: ["3000:3000"] environment: - DATABASE_URL=postgresql://user:pass@db:5432/mydb depends_on: [db] db: image: postgres:15 environment: - POSTGRES_PASSWORD=pass volumes: - db_data:/var/lib/postgresql/data volumes: db_data: ``` Best Practices: Use alpine-based images to minimize size. Run containers as non-root. Use multi-stage builds to keep production images small. Never hardcode secrets — use environment variables or Docker secrets. Common Errors: Running as root inside the container. Including .env files in the image. Large images from not using .dockerignore. Not pinning image versions (using :latest is risky). Interview Questions: What is the difference between a Docker image and a container? How do containers differ from VMs? What is the purpose of a multi-stage build?