What are logs, metrics and traces, and how would you use each one to run a backend service?
What the interviewer wants to hear
- Logs are detailed records of individual events, best when structured
- Metrics are numeric time series used for dashboards and alerts
- Traces follow one request across services with timed spans
- Correlate them with a shared trace or request id
- Alert on symptoms users feel, such as error rate and latency
Model answer
They are the three main signals of observability. Logs are records of single events, like "payment failed for order 9". I write them as structured JSON with fields such as level, user id and request id, so I can search and filter them. Metrics are numbers over time, such as request rate, error rate, latency percentiles and queue depth. They are cheap to store and are what I build dashboards and alerts on, for example alerting when p99 latency or the 5xx rate goes above a threshold. Traces follow one request through every service, showing how long each step took, so I can see that a slow request spent most of its time in one database query. I use OpenTelemetry to produce traces and put the trace id in every log line. Then an alert leads me to a trace, and the trace leads me to the exact logs.
Can you answer it under time pressure?
Take a timed easy round and get scored on every answer.
More easy Backend Developer questions
- How would you design a REST API for a simple blog with posts and comments? Mention URLs, methods and status codes.
- When would you choose a SQL database and when a NoSQL database?
- What is the difference between authentication and authorization? How would you implement both in an API?
- Explain what happens on the backend from the moment a request hits your server until a response is sent.
- What is a database index, and what are its costs? How do you decide which columns to index?
- What is a database transaction, and what do the letters in ACID mean? Give an example where you need one.
- How would you test a new POST /orders endpoint? Which kinds of tests would you write?
- Why do backend teams package services with Docker, and what makes a good Dockerfile?
- Explain the HTTP status code classes and give examples of codes a REST API commonly returns.