KatInterview

Designing a Board Game Engine as a Production Library or Service API

System DesignModel answer
MediumModel answerSystem Designsoftware-engineeringapi-designrefactoring

Last updated

Transform a prototype game engine script into a production-grade software library and stateful HTTP microservice with clean architecture and robust edge-case handling.

Imagine you have just written a working implementation of a two-player grid-based game engine during a coding session.

The core game mechanics operate as follows:

  • The game board has dimensions of $R$ rows by $C$ columns.
  • A turn consists of dropping a colored piece into the bottom of a specific column. This action shifts all pre-existing pieces in that column upward by one position. If the column is completely full, the top piece falls off the top of the board and is removed.
  • The game engine identifies win conditions by finding $K$ contiguous pieces of the same color arranged in any single row or column.

Your current implementation works correctly and passes preliminary test cases, but it exists as a single, unorganized script with global variables, bare arrays, and embedded constants.

The interviewer asks:

"How would you restructure and extend this code so it can be published as a reusable, production-ready software library for other teams—or deployed as a standalone backend API service?"

Explain the specific engineering steps, architectural boundaries, edge-case definitions, and trade-offs required to transform this prototype into production software.

Hints

Hint 1

Distinguish internal state representations (like flat arrays or bitboards) from public interface contracts, ensuring users cannot mutate internal board arrays directly.

Hint 2

Consider subtle domain edge cases caused by column shifting, such as top-piece eviction during full-column inserts and simultaneous multi-player win evaluation.

Hint 3

Explain the operational differences between an in-process library model and a distributed network API, focusing on state management and concurrency controls.