Go Developer interview question
How do you use interfaces idiomatically in Go?
Keep Go interfaces small and define them at the consumer side. They describe the behaviour a caller needs, not a class hierarchy or every capability of a concrete type.
Direct answer
What a strong answer covers
How it works
Idiomatic Go interfaces are discovered, not declared up front: the consumer states the one or two methods it calls, and any type with those methods satisfies it implicitly. Small interfaces compose, are trivial to fake in tests, and avoid coupling a package to a concrete implementation it does not control. Returning concrete types and accepting interfaces keeps the public surface honest about what a function needs.
Example
A service that only needs Read can accept io.Reader instead of a large storage interface. A payment package defines type Charger interface with a single Charge method next to the code that calls it, so the Stripe adapter and the test fake both satisfy it without importing the payment package.
Common mistakes
- Defining a large interface in the producer package and forcing every implementation to match it.
- Introducing an interface with a single implementation only to make mocking possible.
- Returning an interface from a constructor, which hides methods and defeats static checks on the concrete type.
A useful answer structure
Answer from your own work.
Do not memorise a script: use only examples you can explain honestly in follow-up questions.
Open the desktop workspace and rehearse a clear answer in your own words.