Interview questions and model answers
"What does set -euo pipefail do and what are its pitfalls?"
-e exits when a command fails, -u treats unset variables as errors, and pipefail makes a pipeline fail if any stage fails. Pitfalls: -e doesn't trigger inside if conditions, in && or || chains, or for failures hidden in some command substitutions, and commands like grep that return 1 for "no match" need || true when that's acceptable. I add an ERR trap for context and an EXIT trap for cleanup.
"How do you handle pagination and throttling in boto3?"
Use the client's paginators rather than a single call, since most list and describe APIs return pages. For throttling, configure botocore retries with standard or adaptive mode and a higher max_attempts, limit concurrency, and catch ClientError to inspect specific error codes.
"When would you choose Python over Bash?"
Bash for short glue scripts, container entrypoints and command orchestration. Python when there's real logic — JSON or YAML manipulation, API clients with pagination and retries, concurrency, error handling, unit tests — or once a script grows past roughly a hundred lines.
"How do you make an automation script safe to run in production?"
Dry-run by default with an explicit flag to make changes, input validation, clear logging, idempotency so re-runs are harmless, locking against concurrent runs, least-privilege credentials from roles rather than keys, timeouts and retries for network calls, meaningful exit codes, tests (moto for AWS, bats for Bash), and running it through CI or a scheduled job rather than from a laptop.
"Threads or asyncio or processes in Python?"
For I/O-bound work like API calls, threads via ThreadPoolExecutor are simplest and asyncio scales to thousands of concurrent connections. CPU-bound work needs processes because of the GIL. I always bound concurrency to respect API rate limits.
"Write a one-liner to find the top 5 URLs returning 500."
awk '$9 == 500 {print $7}' access.log | sort | uniq -c | sort -rn | head -5 — field 9 is the status and field 7 the path in the combined log format; I'd confirm the format first.