InterviewStack.io LogoInterviewStack.io

Maintainability and Legacy Code Questions

Covers strategies and principles for evolving codebases safely and keeping them easy to understand and change over time. Topics include design principles such as Single Responsibility, Open Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion, removing duplication, establishing appropriate abstraction boundaries, separation of concerns, identifying and remediating code smells, incremental refactoring approaches, regression risk mitigation via tests and feature toggles, backward compatibility and migration strategies, and prioritizing technical debt reduction. Interviewers assess the candidate ability to plan pragmatic refactors, minimize risk during change, and improve long term health of a codebase.

MediumTechnical
73 practiced
You discover duplicated business logic implemented across three services that should behave identically. Evaluate the trade-offs between extracting a shared library, creating a central service for that logic, or keeping duplication with stricter sync processes. Recommend a pragmatic plan for reducing duplication with minimal risk.
HardTechnical
62 practiced
Hard technical coding: A recursive tree traversal in Java currently causes stack overflow for deeply unbalanced trees. Given a method `long sum(TreeNode root) { if (root == null) return 0; return root.val + sum(root.left) + sum(root.right); }`, rewrite this to an iterative approach that avoids recursion and explain performance and memory trade-offs.
HardTechnical
106 practiced
Hard technical coding: Write a Python script concept (pseudocode acceptable) that performs automated refactoring across a repository by transforming deprecated API calls of the form `old_logger.log(level, message)` to `new_logger.log(level, message, context={})` using an AST-based approach. Explain how you would test the script and avoid introducing regressions.
EasyTechnical
65 practiced
You inherit a small legacy Python module where three functions repeat the same input validation and logging steps before performing different actions. Example (inline): `def create_user(data): if not data.get('email'): raise ValueError; log('create', data); ...` and similar code exists in update_user and delete_user. Refactor the example to remove duplication, improve clarity and testability, and explain why your changes improve maintainability. Provide the refactored Python code and brief rationale.
MediumSystem Design
70 practiced
System design: You need to change a widely used database schema field (rename and change type) for a service that serves 5 million users and requires near-zero downtime. Outline a migration strategy that maintains backward compatibility, supports rollback, and minimizes data loss. Include steps for dual reads/writes, backfill, feature flags, monitoring, and eventual cutover.

Unlock Full Question Bank

Get access to hundreds of Maintainability and Legacy Code interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.