The 30 second answer
I'd treat it as an equivalence project, not a rewrite. The running old service is the reference, not its test suite. I write down what "equal" means before writing comparison code, replay the same real requests against both, and compare the response, the database rows, the messages, and even the SQL sequence. Then I prove the comparison can actually fail, with mutation testing and fault injection.
Start from the right reference. The old service's tests describe what someone once expected, not what production does today. Use the running service as the oracle: start it in containers with real databases, feed it a corpus of real requests, and record what it actually produces. The old test suite is still useful, but only as a source of inputs. A team that ported a security-critical verification service from Java to Go in November 2026 found that wherever the old tests and the running service disagreed, the service was right; the tests had stale constants and some compared their input with itself.
Write the equivalence contract first. Before any comparison code, decide what "equal" means for each kind of output:
- Exact match for anything clients depend on directly.
- Field-by-field match for outputs that contain randomness, such as generated IDs or nonces: the raw bytes differ, but every other field must match.
- Column-by-column match for every database row the request writes.
- Explicit substitutes where byte equality is impossible. For values that are unique by design, use cross-verification: each implementation must accept what the other produced. Report any remaining difference as a number, never as "close enough".
Put the clock and randomness behind interfaces, fixed in tests and real in production, or none of these comparisons is reproducible.
Compare every place a request leaves a result. One request can produce a response, database rows, search-index documents and queue messages. Dashboards and downstream consumers read the rows and messages, not the response, so a port that returns a perfect response but writes a slightly different row is still broken. Go one level further and compare the SQL statement sequence and transaction boundaries. In the Java-to-Go port, the first comparison at that level found four differences that every output test had passed, including a lookup that Java made once per request and Go made three times: same answer, three times the load on a hot path.
Prove the tests can fail. "Zero differences" means nothing if the comparison could never see one.
- Mutation testing: deliberately break the code and check that the tests catch it. A mutant that doesn't compile doesn't count as caught.
- Ablation: switch off one validation step at a time and see whether the request corpus notices. If it barely does, the corpus doesn't exercise that step and needs targeted tests.
- Tampering and malformed inputs: a security-critical service is judged by how it fails, so failures must be equal too.
- Fault injection: stop the database mid-test and compare how both services behave. Error handling is behaviour.
- Self-checking known-difference lists: when an accepted difference disappears, the test fails and forces you to remove it from the list, so the list cannot go stale.
Watch for circular validation. Two implementations fed the same wrong input will agree on the same wrong answer. Agreement proves equivalence, not correctness, so keep some independent checks, such as tampering tests and hand-written expected values for critical rules.
Plan the cutover in both directions. While both services share data, the new one must read what the old one wrote and the other way round, and a request prepared by one must be accepted by the other. If the schema belongs to another service, the new service should never run automatic migrations; it should validate the schema at startup and refuse to boot on a mismatch.
Gate phases on named tests. Order phases by dependency (platform, persistence, shared building blocks, core flows, remaining endpoints, cutover), and close a phase only when a list of specific tests is green, not when "tests are green". Port the highest-traffic endpoint early so the riskiest path gets the most measurement time. In production you can add shadow traffic or a strangler-fig rollout, routing a slice of traffic to the new service while comparing results.
What a senior answer sounds like. "I'd make the running system the reference, write the equivalence contract before the comparison code, and compare responses, rows, messages and the SQL sequence. Then I'd prove the harness has teeth with mutation testing, ablation and fault injection, and roll out behind shadow traffic with a rollback path."
Alternate interview scenarios
"All our comparison tests show zero differences. Are we done?"
Not yet. Check that the harness could have found a difference: run mutation testing and switch off validation steps one at a time. If removing a step changes nothing in the results, the corpus never exercised it. Also check that the reference data came from the same runtime version as production.
"The new service returns identical responses but the database CPU went up."
Responses are not the whole behaviour. Compare the SQL statements and transaction boundaries per request; a repeated lookup or a missing batch can triple the load with the same answer.
"The old service's unit tests and the running service disagree. Which one do you port?"
The running service, because that is what clients and downstream systems depend on. Use the tests as inputs, take expected values from the running system, and raise the disagreement as a possible existing bug.
"A benchmark says the new code is fast enough, so we stopped optimising."
First check the configuration it ran on. Record the runtime version, toolchain version, commit and harness mode next to every number. In the Java-to-Go port, a benchmark run on a newer local Go release understated the production numbers by about 2.3 times.