The implementation part was manageable but the 'what would you inspect before making changes' angle tripped me up a bit.
Start by explaining how you would navigate the existing codebase to understand the current architecture, message flow, and validation patterns for AddOrder and CancelOrder. Then outline a design for ModifyOrder that reuses existing patterns, includes robust validation and rejection logic, and considers trade-offs like atomicity and performance. Finally, discuss how you would implement and test the new request end-to-end.
Pro tip: Emphasize that you would first look for existing abstractions and utilities (e.g., validation helpers, order book interfaces) to avoid reinventing the wheel, and that you would write unit tests for edge cases like modifying a non-existent order or invalid price/quantity before writing production code.
Identify the main components: client, server, order book, message handlers, and validation logic. Trace the flow of AddOrder and CancelOrder from client request to server processing to understand patterns and extension points.
Clarify what 'modify' means: does it update price and quantity in-place, or cancel and replace? Determine validation rules: order must exist, new price/quantity must be valid (e.g., positive, within limits), and whether modification is allowed based on order state.
Add a new message type for ModifyOrder, following the existing serialization format. Implement a server-side handler that validates the request, updates the order book, and sends appropriate acknowledgments or rejections.
Reuse existing validation utilities where possible. Handle edge cases: order not found, invalid price/quantity, modification of a filled or cancelled order, and concurrency issues. Return specific rejection reasons.
Write unit tests for the handler and integration tests for the end-to-end flow. Ensure backward compatibility and consider performance impact (e.g., locking, order book updates).
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.