39 questions
DevOps interview questions and answers
Junior questions
1. How does a Docker image differ from a container?
Answer
An image is an immutable template: a set of filesystem layers with metadata such as the start command. A container is a running instance of an image with a thin writable layer, its own processes, network and filesystem. Many containers can be started from one image. Data written inside a container disappears with it unless it is moved to a volume.
Follow-up question: Where is the data of a database running in a container stored, and how do you avoid losing it?
- Course: Docker basics
- Knowledge base: Docker
- Source: docs.docker.com
2. How does a container differ from a virtual machine?
Answer
A virtual machine has its own guest OS on top of a hypervisor, so it is heavier, starts in minutes and is isolated more strongly. A container shares the host kernel and is isolated by kernel features: namespaces for the view of processes and network, cgroups for resource limits. That is why a container starts in seconds and takes megabytes. The price: all containers depend on one kernel, so isolation is weaker than with a VM.
Follow-up question: Why can't a Linux container run on a Windows kernel without an extra layer?
- Course: Docker basics
- Knowledge base: Docker
3. What is CI and why does a team need it?
Answer
Continuous Integration is the practice where every code change is automatically built and checked on a server: installing dependencies, linter, types, tests, build. A developer learns within minutes that a change broke something, not a week after merging. CI also guarantees the check runs in a clean environment, not only on the author's laptop. It usually runs on every pull request and blocks the merge while checks are red.
Follow-up question: How does Continuous Delivery differ from Continuous Deployment?
- Course: CI/CD with GitHub Actions
- Knowledge base: GitHub Actions
4. How does Continuous Delivery differ from Continuous Deployment?
Answer
Both extend CI: after successful checks the build moves through the pipeline toward a release. In Continuous Delivery the artifact is always ready to ship, but a human decides to press the deploy button. In Continuous Deployment every change that passes all automatic checks reaches production with no manual step. The latter requires very reliable tests, feature flags and fast rollback.
Follow-up question: What are the risks of auto-deploying to production on every commit?
- Course: CI/CD with GitHub Actions
- Knowledge base: GitHub Actions
5. What are Docker image layers and how do they affect build speed?
Answer
Each Dockerfile instruction such as
RUNorCOPYcreates a layer. Docker caches layers: if an instruction and its input did not change, the layer comes from the cache. But a change in one layer invalidates the cache of all following layers. So rarely changing things go first and the application code is copied last: first the dependency file and the install, then the rest.Follow-up question: What does
.dockerignoredo and why is it needed?- Course: Docker basics
- Knowledge base: Docker
- Source: docs.docker.com
6. How does a container keep data and how do you reach it from outside?
Answer
Data that must outlive the container goes into a named volume or bind mount: it lives outside the container's writable layer. A container is network-isolated by default, so a port is published with
-p host:container. Containers in the same user-defined network see each other by service name through built-in DNS. Content without a volume disappears when the container is removed.Follow-up question: How does a named volume differ from a bind mount?
- Course: Docker basics
- Knowledge base: Docker
7. What are a Pod and a Deployment in Kubernetes?
Answer
A Pod is the smallest unit of execution: one or more containers with shared network and storage. A Pod is temporary: if it dies, nobody restores it on its own. A Deployment describes the desired state: which image and how many replicas. A controller makes sure the actual state matches the desired one, recreates failed Pods and performs rolling updates.
Follow-up question: Why do you not call a Pod by its IP directly?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes
- Source: kubernetes.io
8. Why do you need Service and Ingress in Kubernetes?
Answer
Pod IP addresses change, so a Service provides a stable name and virtual address that balances traffic across live Pods chosen by a label selector. Service types:
ClusterIPonly inside the cluster,NodePortandLoadBalancerfor external access. Ingress describes HTTP routing rules by host and path and terminates TLS. The rules do nothing without an ingress controller, for example one based on Nginx.Follow-up question: How does ClusterIP differ from LoadBalancer?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes, nginx
9. Why are config and secrets not hardcoded in code and images?
Answer
The same image must run in dev, staging and prod, and only the configuration should differ, supplied through environment variables or mounted files. Secrets in code end up in git history, in the image registry and with everyone who has repository access. They are stored in a secrets manager or encrypted CI variables and passed in at runtime. A committed key is considered compromised: it is rotated, not just removed from the repo.
Follow-up question: Why does deleting the secret in the next commit solve nothing?
- Course: Docker and deployment
- Knowledge base: Docker
10. What is observability and how do logs, metrics and traces differ?
Answer
Logs are individual events with context: what exactly happened and with what data. Metrics are numbers over time, cheap to aggregate and alert on: RPS, error rate, latency. A trace shows the path of one request across several services with spans and time in each. A metric says something is wrong, a trace says where, a log says why. They are linked by a shared request id or
trace_id.Follow-up question: Where do you start investigating when an alert fires?
- Knowledge base: Prometheus, OpenTelemetry, Grafana Loki
Middle questions
1. A Node app image weighs over a gigabyte, and every one-line code change reinstalls all dependencies. How do you fix the Dockerfile?
Answer
Each instruction makes a layer, and a changed layer invalidates the cache of the following ones. If
COPY . .comes beforenpm install, any code edit reinstalls dependencies. First copypackage.jsonwith the lock file, runnpm ci, and only then the rest of the code. For size, use multi-stage: build in one stage, and only the built code and production dependencies reach the final slim image viaCOPY --from. Also add.dockerignore, run as a non-root user and pin the image tag instead oflatest.Follow-up question: Why is
npm cibetter thannpm installin a Dockerfile?- Course: Docker basics
- Knowledge base: Docker
- Source: docs.docker.com
2. A Dockerfile copies a token into the image and the next command deletes the file with
rm. Is the token gone, and how should you pass a secret into a build correctly?Answer
It is not gone. Layers are only added:
rmcreates a new layer with a deletion mark, while theCOPYlayer stays in the image and goes to the registry. Anyone who can pull will unpack the layer and read the token. The right way is a BuildKit secret:RUN --mount=type=secret,id=npmrctogether withdocker build --secret, so the secret is available only during that command and does not land in a layer.ARGis not suitable either, because values stay in the image history.Follow-up question: How do you make sure a finished image contains no secrets?
- Course: Docker basics
- Knowledge base: Docker
- Source: docs.docker.com
3.
docker stopon your Node container always waits 10 seconds and then kills it. Why, and what do you do about it?Answer
docker stopsendsSIGTERMto the process with PID 1 andSIGKILLafter the timeout. A PID 1 process in Linux has no default signal handlers, so if the app does not listen forSIGTERM, it does not exit. A common cause is also starting throughnpm startor the shell form ofCMD: the shell gets the signal, not Node. Fix: exec formCMD ["node", "dist/main.js"], aSIGTERMhandler that closes the server and connections, and if needed the--initflag or tini.Follow-up question: What should graceful shutdown do in an HTTP server?
- Course: Docker and deployment
- Knowledge base: Docker
4. In docker compose the API fails with
connection refusedto Postgres even thoughdepends_onis set. Why, and how do you fix it?Answer
A plain
depends_ononly controls container start order, not service readiness. The Postgres container is already running, but the database is still initializing. The solution: ahealthcheckon the database service (for examplepg_isready) anddepends_onwith theservice_healthycondition. Also the app should retry connecting with backoff, because the database can restart in production too.Follow-up question: How does liveness differ from readiness?
- Course: Docker and deployment
- Knowledge base: Docker
- Source: docs.docker.com
5. How do liveness, readiness and startup probes differ in Kubernetes?
Answer
Liveness answers whether the process is alive: on failure the kubelet restarts the container. Readiness says whether the Pod is ready to accept traffic: on failure it is removed from the Service endpoints but not restarted. A startup probe protects a slow start: until it passes, the other probes do not run. A typical mistake is checking an external dependency such as the database in liveness, so its failure restarts all Pods and makes things worse.
Follow-up question: What happens during a rolling update without a readiness probe?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes
- Source: kubernetes.io
6. What are resource requests and limits in Kubernetes and what happens when they are exceeded?
Answer
A request is the guaranteed minimum the scheduler uses to pick a node. A limit is the ceiling. Exceeding the CPU limit causes throttling, and the process slows down. Exceeding the memory limit causes an OOMKill: the container is killed and restarted. Without requests the scheduler packs nodes blindly, and without limits one Pod can eat its neighbors' resources. The ratio of requests to limits also defines the Pod's QoS class, which determines eviction order.
Follow-up question: How do you notice that a Pod is being CPU throttled?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes
7. What are ConfigMap and Secret for in Kubernetes, and does a Secret really protect data?
Answer
A ConfigMap stores non-secret configuration, a Secret is meant for sensitive values. Both can be supplied as environment variables or mounted files. But a Secret is by default only base64-encoded, not encrypted, and is stored in etcd. So you enable etcd encryption at rest, restrict access through RBAC and, for serious cases, connect external stores such as Vault or cloud secret managers. Mounted files update without a restart, environment variables do not.
Follow-up question: How do you update config in running Pods without downtime?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes, Helm
- Source: kubernetes.io
8. Describe a pipeline for a backend service. What are the stages, how does cache differ from artifacts, and how do you protect the deploy?
Answer
Typical stages: install dependencies, linter and types, unit tests, image build, integration tests, push to the registry, deploy. A cache speeds up repeated runs (for example downloaded dependencies) and can be lost without harm. An artifact is a build result passed to later stages, and the release uses exactly that so nothing is rebuilt. The deploy is protected by: secrets only in protected variables, production deploy only from the main branch, manual approval or environment protection, and minimal token permissions.
Follow-up question: How do you make sure a pipeline running on a PR cannot read production secrets?
- Course: CI/CD with GitHub Actions
- Knowledge base: GitHub Actions, GitLab CI/CD
- Source: docs.github.com
9. How do you secure a workflow in GitHub Actions?
Answer
Set minimal
permissionsforGITHUB_TOKENand use OIDC instead of long-lived cloud keys. Pin third-party actions to a commit SHA, not a movable tag. Do not print secrets in logs or expose them to workflows from forks. The dangerouspull_request_targettrigger combined with checking out PR code lets foreign code run with access to secrets, so avoid it. Untrusted input such as a PR title is not interpolated directly into shell commands.Follow-up question: What is script injection in a workflow and how do you avoid it?
- Course: CI/CD with GitHub Actions
- Knowledge base: GitHub Actions
10. What is Infrastructure as Code and how does Terraform work?
Answer
Infrastructure as Code describes infrastructure as code in a repository, so it can be reviewed, versioned and reproduced. Terraform is declarative: you describe the desired state,
terraform plancompares it with the state and shows the changes, andapplycarries them out. The state file maps resources to real objects, so it is kept in a remote backend with locking, not in git. Manual changes in the console create drift, which the next plan will show.Follow-up question: Why must state not be committed to git, and what secrets might it hold?
- Knowledge base: Terraform, OpenTofu
- Source: developer.hashicorp.com
11. Compare rolling, blue-green and canary deployments.
Answer
Rolling gradually replaces old instances with new ones: no downtime and no double resources, but both versions run side by side for a while. Blue-green keeps two full environments and switches traffic at once, rollback is instant, but double infrastructure is needed. Canary sends a small percentage of traffic to the new version and widens it when metrics look fine, which is the lowest risk but needs automatic metric analysis and traffic routing. In all three the database schema must be compatible with both code versions.
Follow-up question: How do you ship a release that drops a column without downtime?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes, Argo CD
12. How do you organize dev, staging and prod, where do config and secrets live, and what do you do when a key was committed to the repo?
Answer
Environments differ only in configuration, the image is the same. Staging is as close to prod as possible in versions and topology, but with different data and keys. Secrets live in a secrets manager or encrypted CI variables, not in the repo. If a key was committed, revoke and rotate it immediately: rewriting history does not help, because it may already be copied. Then check the key's usage logs and add a secret scanner to pre-commit and CI.
Follow-up question: How do you prevent secrets from being committed again automatically?
- Course: Docker and deployment
- Knowledge base: Terraform
13. How does RED differ from USE? What are SLI, SLO and error budget, and which alerts wake a person at night?
Answer
RED describes a service from the user's view: Rate, Errors, Duration. USE describes a resource: Utilization, Saturation, Errors, for example for CPU or disk. An SLI is a measured indicator such as the share of successful requests, an SLO is the target value, say 99.9% over 30 days. The error budget is the allowed share of failures, 0.1%, and while it is not exhausted the team can take risks with releases. At night you are paged only for symptoms that affect users or burn the budget quickly, while a disk at 70% becomes a ticket for the morning.
Follow-up question: Why is an alert on 'CPU > 80%' usually bad?
- Knowledge base: Prometheus, Grafana
- Source: sre.google
14. What metric types does Prometheus have and why is a histogram almost always used for HTTP latency?
Answer
A counter only grows (number of requests), a gauge moves both ways (memory, queue), a histogram spreads values across buckets, a summary computes quantiles on the client side. Histograms aggregate across instances: you can sum the buckets of 4 pods and compute the overall p99 with
histogram_quantile. Summary quantiles cannot be averaged across instances, the result is wrong. The downside of a histogram is that accuracy depends on the choice of bucket boundaries.Follow-up question: How do you get a rate in requests per second from a counter?
- Knowledge base: Prometheus
- Source: prometheus.io
15. A team has 200 alerts a day, everything is red, and nobody reacted to a real incident for 40 minutes. What do you do?
Answer
This is alert fatigue: people stop trusting the noise. Every alert should require human action right now, otherwise it is deleted or turned into a dashboard or ticket. Alert on user-facing symptoms (errors, latency, SLO), not on every cause. Group and deduplicate in Alertmanager so a host failure does not produce 140 messages. Add a runbook with steps to each alert. Regularly review which alerts fired for nothing and clean them up.
Follow-up question: How do you make sure one node failure does not produce a hundred alerts?
- Knowledge base: Prometheus, Grafana
16. How do you set up logging so that one
requestIdortrace_idfinds all lines of a request across all services?Answer
Logs are written in a structured form (JSON), not free text. At the request entry you take the identifier from a header such as
traceparent, or generate a new one, put it into the context (in Node, AsyncLocalStorage) and add it to every log line automatically. All outgoing calls pass the same identifier on in headers. Then in Loki or Elasticsearch one search by that field shows the whole path of the request. Secrets and personal data do not get into logs, they are masked.Follow-up question: What is W3C Trace Context and why the
traceparentheader?- Knowledge base: Grafana Loki, ELK Stack, OpenTelemetry
17. The payment service started responding in 30 seconds and the whole API went down. Why is a slow dependency worse than a dead one, and what helps?
Answer
A dead dependency gives a fast error, while a slow one holds connections, threads and memory until the queue of requests exhausts the resources of the whole service. Protection: short timeouts on all calls, a circuit breaker that opens after a series of failures and fails fast instead of waiting, limiting concurrent calls (bulkhead), and a fallback or degraded functionality. After a pause the breaker lets trial requests through and closes if the dependency recovered.
Follow-up question: How do you choose a timeout value for a call to another service?
- Knowledge base: OpenTelemetry
18. Why are retries at every level of a service chain dangerous during an outage, and how do you configure them correctly?
Answer
If each of three layers makes 3 attempts, the bottom service gets up to 27 requests for one client request: a retry storm finishes off a dependency that is already degrading. The right way: retry only idempotent operations and only errors that may pass, use exponential backoff with jitter, limit the total retry budget and retry at one level, not at all of them. Dangerous operations such as charging money are protected with an idempotency key.
Follow-up question: What is an idempotency key and how does the server check it?
- Knowledge base: Apache Kafka
19. An API runs on a single server. You need 99.9% availability and five times the load headroom. What do you change?
Answer
Remove the single point of failure: several instances behind a load balancer with health checks, across zones or hosts. The app must be stateless: sessions in Redis or JWT, files in object storage rather than on the instance disk. The database becomes the next bottleneck: read replicas, automatic failover, backups. Add autoscaling on a metric, a cache for hot reads and verify everything with a load test.
Follow-up question: Why might a user be randomly logged out after moving to 3 instances?
- Knowledge base: Kubernetes, Redis
20. A nightly
pg_dumpruns. At 14:03 someone ranDELETEwithoutWHERE. What will such a backup achieve and what would help better?Answer
The nightly dump restores the state at 00:00, so all changes over 14 hours are lost. It is better to have continuous WAL archiving together with base backups: then you can do point-in-time recovery and restore to 14:02. Restoration is done on a separate instance, from which the needed data is returned to prod. A backup without a tested restore guarantees nothing, so restores are practiced regularly and RTO and RPO are measured. Copies are kept separate from the main server.
Follow-up question: What are RPO and RTO and how do they affect the choice of backup strategy?
- Knowledge base: PostgreSQL
- Source: postgresql.org
21. The incident is closed. How do you write a postmortem and what should it contain?
Answer
A blameless format: focus on the system and processes, not on the person who pressed the button. Parts: a short summary and user impact, a timeline with detection and mitigation times, the root cause and contributing factors, what went well, and concrete actions with owners and deadlines. Good actions reduce the chance or impact of a repeat rather than amounting to 'be more careful'. The document is shared with the team and action completion is tracked.
Follow-up question: How do you tell the root cause from contributing factors?
22. How do you make a Docker image and container run more secure?
Answer
Use a minimal base image (slim or distroless) and pin the version, ideally by digest. Run as a non-root user, with a read-only filesystem where possible and without extra capabilities. Scan images for vulnerabilities in CI and keep secrets out of layers. Do not mount
docker.sockand do not use--privilegedwithout dire need, since that equals root on the host. Use a trusted registry, with signed images where possible.Follow-up question: Why is access to
docker.sockequal to root on the host?- Course: Docker and deployment
- Knowledge base: Docker
- Source: docs.docker.com
23. How do you organize a fast release rollback?
Answer
Every release is an immutable versioned image with a tag that can be started again in seconds: in Kubernetes that is
kubectl rollout undo, in compose going back to the previous tag. Code rollback is safe only if the database schema is compatible with the old version, so migrations are made backward compatible. New features are hidden behind a feature flag and switched off without a release. Rollback is automated on metrics (the error rate rose) and periodically checked to work.Follow-up question: What do you do if a migration has already irreversibly changed data?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes, GitHub Actions
Senior questions
1. How do you ship a new API version without downtime if the release also changes the database schema?
Answer
Migrations follow the expand and contract style. First add new columns or tables that do not break the old code version. Then ship code that writes to both places and reads from the new one, and backfill data with a background script. Only when no old version is running, drop the old columns in a separate release. The code itself is rolled out with rolling or canary, with readiness probes and graceful shutdown. This way even a failed release can be rolled back without rolling back the database.
Follow-up question: Why is renaming a column in one step dangerous?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes, PostgreSQL
2. After a release Prometheus started crashing with OOM, and a label with values like
user_idappeared in the metrics. What happened and what do you do?Answer
Each unique combination of label values is a separate time series. A label with unbounded values, such as
user_id, a URL with an id ortrace_id, creates millions of series, and Prometheus runs out of memory. Fix: remove that label from the metric, normalize the path to a route template, and keep individual identifiers in logs and traces. For diagnosis, look at the top metrics by series count, and addsample_limitto the config as a safeguard. Cardinality is also critical for Loki and other label-based systems.Follow-up question: Why is the same dangerous with labels in Loki?
- Knowledge base: Prometheus, Grafana Loki
3. SLO 99.9% over 30 days. The alert
error_ratio > 0.001 for 5mwakes people at night over every blip. How do you redo it?Answer
A simple threshold does not account for how much error budget is actually being spent. Burn rate shows how many times faster than normal the budget is burning. You build a multi-window alert: for example fast burn (burn rate around 14 over a 1 hour window, confirmed by a shorter 5 minute window) pages a person, slower burn (burn rate 6 over 6 hours) creates a ticket. The short window removes false alarms after the problem is already over. This way a night call means the budget is really disappearing.
Follow-up question: How long until the budget is exhausted at burn rate 14?
- Knowledge base: Prometheus, Grafana
- Source: sre.google
4. At 3 AM an alert fires: 30% of requests return 500, and you are on call. What are your first actions?
Answer
First I confirm the scale and user impact, announce it in the incident channel and take the incident owner role. The goal of the first minutes is mitigation, not finding the root cause. I look at what changed: a recent deploy, config, a dependency, traffic. If there is an obvious culprit, I roll back the release or switch off a feature flag. Then I narrow the cause using metrics, logs and traces. After stabilization I write a blameless postmortem: timeline, causes, actions so it does not repeat.
Follow-up question: When do you roll back a release and when do you fix forward?
5. What is GitOps and how does it differ from deploying from CI?
Answer
In GitOps the desired cluster state is described in git, and an agent inside the cluster, such as Argo CD or Flux, constantly compares it with the real state and syncs it. Changing an environment is a commit or PR, so you get review, audit and rollback through
git revert. The difference from push deploys from CI: CI needs no direct access to the cluster, keys stay inside, and the agent fixes drift and manual changes. The downside: separate discipline for secrets and for two repositories, code and manifests.Follow-up question: How do you store secrets safely in GitOps?
- Course: Kubernetes: the basics
- Knowledge base: Argo CD, Helm, Kubernetes
- Source: argo-cd.readthedocs.io
6. How does horizontal autoscaling work in Kubernetes and what are its pitfalls?
Answer
The Horizontal Pod Autoscaler periodically compares the current metric, usually CPU, with the target and changes the replica count. It depends on defined requests: without them CPU percentage cannot be computed. Pitfalls: slow start of new Pods, so a peak can arrive before they are ready; scaling on CPU alone suits queue or I/O bound work badly, there you use custom metrics or KEDA; new Pods still have to fit onto nodes, so a Cluster Autoscaler is needed. Also set a minimum replica count and a stabilization window to avoid flapping.
Follow-up question: Why won't HPA help if the bottleneck is the database?
- Course: Kubernetes: the basics
- Knowledge base: Kubernetes
- Source: kubernetes.io
Train these questions
Study the cards, answer by text or voice and get an AI grade. Needs a signed in account.
Answer out loud and get graded
Here you get the questions with model answers. In the ShortLesson app you answer yourself, by text or voice, and AI grades the answer against the rubric and asks a follow-up, like a real interviewer.
The app is coming to the stores soon.
Other topics
- JavaScript interview questions and answers
- TypeScript interview questions and answers
- React interview questions and answers
- Frontend performance interview questions and answers
- Node.js interview questions and answers
- HTTP interview questions and answers
- SQL interview questions and answers
- Databases interview questions and answers
- Git interview questions and answers
- Algorithms interview questions and answers
- System design interview questions and answers
- Web security interview questions and answers
- Testing interview questions and answers