Top 3 Protocols Interview Questions
Browse 3 real-world technical and behavioral interview questions about Protocols. Review scenarios, edge cases, and architectural best practices.
When would you reach for an abstract base class rather than a Protocol, and what does isinstance check in each case?
Use a Python ABC when you need nominal inheritance and runtime instantiation checks; use a Protocol when a type checker should accept any object with the required methods, even without inheritance. Use this abstract base classes answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects protocols to the point an interviewer is testing.
If you were writing a small value type in Python, which dunder methods would you implement, what would you let a dataclass generate, and how does super() decide what to call?
Implement the dunders that opt your type into a protocol, treating repr, eq and hash as one decision, and let a dataclass generate the boilerplate when the fields are the identity. super() follows the C3 linearisation of type(self), so it calls the next class in the MRO rather than your own base.
When would you choose UDP over TCP, given that TCP is reliable and UDP is not?
TCP guarantees an ordered byte stream and pays for it with head-of-line blocking and retransmissions that arrive too late to be useful. UDP is right when a late packet is worthless, when you need multicast, or when you intend to build your own reliability with different trade-offs.