InterviewLegend

Design Battleship as an Online Game

Commonly asked
Alex Chen25 min readGuide updated
In this lesson
  • Turn the in-memory Battleship classes into game sessions that survive restarts and deploys
  • Settle turns and concurrent shots with one conditional write and an idempotent move id
  • Work through push updates, hidden fleets, timeouts and the numbers you would watch in production

Understanding the problem

The prompt

Something like this: you've just built Battleship as a few classes running in one process. Now people want to play it online, two players per game and many games at once. How would you deploy it to production, and what performance and system problems would you expect?

A senior candidate in a November 2026 GitHub loop got Battleship as the second of two coding rounds. After the object-oriented part, the interviewer moved on to deploying it as an online game and to the performance and system issues of running it. What follows is something like that conversation, worked from the classes you'd have on screen at that point.

If you haven't built the game yet, start with the Battleship coding lesson. It ends with a Game that owns two boards and a turn number. That object works fine on your laptop. Put it behind a web server and it breaks in four ways at once. A restart wipes every game in progress. Two requests for the same game can arrive in the same millisecond. A phone on a bad connection resends a shot it already fired. And the opponent's browser has no idea a shot happened until something tells it. The scale is small. The hard part is keeping every game correct while machines restart and networks misbehave.

The GitHub angle
Keep your own classes in the answer. The follow-up came straight after the coding part, so the interviewer has your Board and Game on screen. Point at them: "this object becomes a row plus a list of shots, and this method becomes one transaction." Tying the design back to your code shows you know what changes once it runs online.

Requirements

Functional requirements

Agree on the surface in the first few minutes. A player creates a game and gets an invite code to send a friend. The friend joins with it. Each player places a fleet, and the server checks it with the same rules as the coding round. Then they take turns firing, each shot comes back as a miss, a hit or a sunk ship, and sinking the last ship ends the game. The opponent sees every shot within a moment. A player who closes the tab can come back and pick up where the game stands.

In scope

  • Create a game, share an invite code, join it
  • Place a fleet, validated on the server
  • Fire a shot on your turn and get miss, hit or sunk back
  • See the opponent's shots right away, and rejoin after a disconnect
  • End stalled games when a player walks away

Below the line (call it out, then skip)

  • Matchmaking with strangers and skill ratings
  • Chat, friends lists and leaderboards
  • Spectators and replays for people outside the game
  • Payments, cosmetics and anything about accounts beyond sign-in

Non-functional requirements

Correctness comes first. A shot must count exactly once, and turns must alternate. Nor can a game ever show two winners. Someone who retries a shot because the network hung should get the original answer back. Those rules make the shot write the one place that needs strong consistency. Latency matters, but loosely. A shot should come back in under 200 milliseconds, and the opponent should see it within about a second. Players think for seconds between moves, so nothing here needs to be fast in the way a trading system does. The other rule is secrecy. A client must never receive the other fleet's positions, even inside a response it doesn't display. The browser belongs to the player. Anything sent to it can be read. If the interviewer has no numbers, propose some. Say 50,000 games live at the evening peak, one shot every five seconds per game, and about 100 shots per game across both players.

  • Live games at peak: 50,000. Two players each, so about 100,000 open connections to keep alive.
  • Shots at peak: about 10,000 a second. Each game produces one shot every five seconds: 50,000 divided by 5.
  • One game: about 8 minutes. About 100 shots at five seconds each is 500 seconds.
  • Hot state: about 200 MB. Two 10 by 10 boards, the classic 17 ship cells per fleet and up to 200 shots fit in a few KB. 50,000 games at 4 KB is 200 MB.

All the live state fits in the memory of one machine, and 10,000 small writes a second is within reach of one well-sized database. Tell the interviewer that early. Scale won't decide this design. Failure handling will.

The data model, in words

Three records cover it. A game holds its two players, its status and whose turn it is. The status starts as waiting for an opponent, moves to placing ships, then to in play, and ends as finished. A game also keeps a move_count, the number of accepted shots so far. That counter doubles as a version number. Every shot raises it by one, so "the game is at move 7" says exactly which state a request was looking at.

A fleet is one player's ships in one game: each ship's name and the cells it covers. It's written once, when the player confirms placement, and never changes after that. A shot is one accepted move. It records the game, its move number, the player, the cell, the result, and the move_id the client made up before sending it. The board itself isn't stored anywhere. It's the fleet plus the list of shots, rebuilt in memory in microseconds.

Where each record lives
TableFields
gamesgame_id · player_one · player_two · status · turn · move_count · turn_deadline · winner
fleetsgame_id · player · ships (name and cells for each)
shotsgame_id · move_number · player · row · col · result · move_id
All three live in Postgres. Shots are keyed by game and move number, so two writes for the same move collide on the key. A unique index on game and move id makes a retried shot find the row it already wrote.

This is the coding round's object model laid flat. The Game's turn and winner become columns. The Board's map from cell to ship becomes the fleet record, and its set of fired cells becomes the shots table. Nothing about the rules changed. The objects are now loaded per request.

The API

Five HTTP calls and one live connection. Firing is the only call that changes the game while it's in play, so it's the one that carries a move id. The live channel is a WebSocket, a connection the browser keeps open so the server can push a message the instant the opponent moves.

The interface
RequestFire-and-forget
Player appGame APIstart a game
POST /games
game_id, invite_code
Player appGame APIjoin with the code a friend sent
POST /games/{game_id}/join { invite_code }
player number
Player appGame APIplace your fleet
PUT /games/{game_id}/fleet { ships }
status
The server checks bounds and overlap with the coding round rules. A client is never trusted to place ships.
Player appGame APIfire a shot
POST /games/{game_id}/shots { move_id, row, col }
move_number, result
The same move id always gets the first result back, so a retried shot never fires twice.
Player appGame APIload the game, or catch up after a reconnect
GET /games/{game_id}?after={move_number}
status, turn, your fleet, moves after the one given
Never includes the opponent's ship cells, only the results of shots at them.
Realtime gatewayPlayer applive moves for this game
WebSocket /games/{game_id}/live
one message per move, with its move number

The architecture end to end

First, take the game out of server memory. The services that handle requests hold nothing between calls, and the game lives in a database every machine can reach. A separate gateway holds the open connections and pushes moves out. In the diagram, blue is the player's device, violet is a service we run, amber is a channel that moves messages, and green is stored state.

Loading diagram...

1) Create and join. Player one calls create. The Game API inserts a game row in the Game store with a random invite code and returns it. Their friend joins with that code, which fills in the second player and moves the game to placing ships. Nothing slow happens here, and nothing lives in memory. A deploy in the middle of this changes nothing, since the next call can land on any machine.

2) Place ships. Each player sends their full fleet at once. The API runs the placement checks from the coding round: inside the grid, no overlap, the right ship lengths. Then it writes the fleet. When both fleets are in, the game moves to in play with player one to shoot. The fleet is checked on the server because a modified client could otherwise send ships off the grid, or no ships at all, and never lose.

3) Fire. The player's app makes up a move id, for example a random UUID, and sends it with the cell. The API loads the game, the opponent's fleet and the shots so far, about 4 KB of data, and resolves the shot with the coding round's logic. Then one transaction inserts the shot and advances the turn, but only if the game is still where the API found it. At 10,000 shots a second that's 10,000 small transactions. Who wins when two shots race is the second deep dive below.

4) Tell the opponent. After the commit, the API publishes the move on the Game event channel. The Realtime gateway holding both players' connections receives it and pushes it down each WebSocket. The shooter already has the result in the HTTP response, so the push mainly matters for the opponent. How a player who dropped off gets the moves they missed is the third deep dive.

5) Finish or time out. The shot that sinks the last ship sets the winner and the finished status in the same transaction. If a player stops moving, the Turn timer ends the turn when its deadline passes, and after a few missed turns it ends the game as a forfeit. The Load balancer in front of all this has one job beyond spreading load: keeping each WebSocket on the same gateway for its whole life.

Technology choices

  • The Game store is Postgres. A shot has to insert one row and update another atomically, with a uniqueness check on the move id. That's a transaction plus a unique index, which a relational database does well. Run it with a standby replica so a failed primary can be replaced in seconds. If 10,000 writes a second gets tight, split games across databases by game id.
  • The Game API runs as containers behind the load balancer, scaled on CPU. It holds nothing between requests, so a rolling deploy just swaps machines. The failure to plan for is a slow database, which shows up here first as requests waiting for a connection.
  • The Realtime gateway speaks WebSockets. Players need the opponent's move pushed to them, and polling would cost a request per player per second. A gateway machine that dies drops its connections. Those clients reconnect elsewhere and catch up by move number.
  • The Game event channel is Redis pub/sub. It delivers each message to whoever is subscribed at that moment and keeps nothing, which is fine because Postgres holds the truth. If Redis is down, moves still commit and players fall back to fetching the game every few seconds.
  • The Turn timer is a scheduled job that queries games whose turn deadline has passed, using an index on that deadline column. A delayed queue message per turn works too, but the query is simpler, and a restarted timer just runs it again.

Teams run different tools, so the brand matters less than the reason. Be ready to say why a shot needs a transaction and why the push channel is allowed to lose messages.

The GitHub angle
If your team runs Ruby on Rails, map the design onto it. The game is a model, the move count works like Rails' optimistic locking column, and the WebSocket side resembles Action Cable. Concrete mapping to a real framework lands better than abstract boxes.

Potential deep dives

Where does the game state live?

Run the numbers first. At 50,000 live games, a restart that drops in-memory state ends 50,000 games for 100,000 people at once. Teams deploy several times a day. So any answer that keeps games in one process's memory turns every deploy into an outage for everyone mid-game.

BadKeep the Game objects in server memory

Approach

Run the coding round's classes inside the web server, with a map from game id to Game object. Pin each game's players to that server with sticky sessions so every request finds the object.

Challenges

A crash or deploy wipes every game on that server. Sticky routing breaks the moment the server restarts, and it makes load uneven, because a server can't hand off a busy game. Two servers can't share a game at all. It's fine for a demo and falls apart on the first deploy.

GoodSerialize each game into Redis after every move

Approach

Store each game as one value in Redis, keyed by game id. Each shot reads the value, runs the shot through the Game object, and writes all of it back. Redis answers in well under a millisecond, and every API machine can reach every game, so the servers become stateless.

Challenges

Read, change, write back is a race. Two shots that read the same value both write, and the second overwrites the first. Redis can guard against that with a version check on write, but then you're building transactions by hand. Redis also keeps data in memory and copies it to disk only every second or so, so a crash can lose the last moves of thousands of games.

GreatPostgres as the record, with the shot as an append

Approach

Keep the game row, the two fleets and an append-only list of shots in Postgres. A shot inserts one row and updates the game row in one transaction, guarded by a condition on the turn. Nothing is rewritten wholesale. A fleet never changes after placement, and a shot never changes once written. Rebuilding a board means replaying at most 200 shots, which takes microseconds.

Challenges

Every shot now costs a database round trip, a few milliseconds instead of a fraction of one, which is fine against a 200 ms target. At 10,000 transactions a second the primary needs headroom, so plan to split by game id if traffic grows. The win is that a committed shot survives any app crash, and the shots table is a full history for debugging or replays.

Postgres earns its place over Redis through the history and the transaction. Speed favors Redis. A game is short and small, so you could keep a copy of the hot game in memory as a cache, but every shot still has to commit before you answer. Say that out loud. It's the difference between a cache and a source of truth, and interviewers listen for it.

How do we stop two shots landing on one turn?

In the coding round, a check like "is it your turn?" followed by a change can't be interrupted. Online, two requests for one game run on two machines at the same time. Three things cause it in practice. A player double-taps the fire button. A phone times out and resends the shot. Or a buggy or modified client fires on the opponent's turn. Each one, handled carelessly, gives a player two shots or records one shot twice.

BadCheck the turn in code, then write

Approach

Load the game and check that it's this player's turn. Then resolve the shot and save. All the checks run in the API, as they did in one process.

Challenges

Two requests can both load the game before either saves. Both see "your turn", both resolve, both write. The player gets two shots, or the second write erases the first. It passes every single-user test and fails the first time someone double-taps on a slow connection.

GoodLock the game row for the length of the shot

Approach

Open a transaction and load the game row with a row lock, which makes any other transaction that wants the same row wait. Check the turn, resolve the shot, insert it, advance the turn, commit. The second request waits, then sees it's no longer this player's turn and gets rejected.

Challenges

It's correct and easy to explain. Each lock holds for only a few milliseconds, and only one game's two players ever compete for it, so waiting stays rare. It still holds a database connection open while the API does its work, and it doesn't solve the retry. A resent shot arrives after the first committed, finds it's not the player's turn, and the player sees an error for a shot that did land.

GreatA conditional write plus an idempotent move id

Approach

Read the game without a lock and resolve the shot in memory. Then commit with a condition: advance the turn only if the turn and move count are still what we read. Insert the shot in the same transaction. Zero rows updated means someone else moved first. The client's move id has a unique index, so a resent shot hits the existing row and gets its stored result back.

Challenges

Look up the move id before checking the turn. Otherwise a resent shot gets "not your turn" when it should get its result. The client must make the move id once per tap and reuse it on every retry. A new id per retry defeats it.

The guard fits in one statement, and the condition at the end does the work.

sql
UPDATE games SET turn = 2, move_count = 8
WHERE game_id = 'g1' AND turn = 1 AND move_count = 7;
-- 1 row: our shot counts. 0 rows: someone moved first.

Two players can never fire at the same moment legitimately, since only one has the turn. So conflicts are rare, and the optimistic version (try, and retry on a miss) beats holding a lock. The handling contention lesson compares locks and conditional writes in general.

How does the other player see a shot right away?

The shooter gets the result in the HTTP response. The opponent has no request in flight, so something has to tell them. With 100,000 players connected at peak and a move every five seconds per game, the choice of channel decides most of the load on the system.

BadPoll the game every second

Approach

Each app calls the game endpoint every second and redraws when a new move appears.

Challenges

That's 100,000 requests a second at peak, ten times the real shot traffic, and almost all of them return "nothing new". Every one hits the API and probably the database. Slow the polling to five seconds and the opponent waits up to five seconds to see a shot, which feels broken in a turn-based game.

GoodLong polling

Approach

The app asks "anything after move 7?" and the server holds the request open until a move arrives or about 30 seconds pass. Moves show up right away, and a quiet game costs one request every 30 seconds instead of one every second.

Challenges

Each waiting request still ties up a connection, and the server needs a way to wake the right waiting requests when a move commits. That's the same publish and subscribe plumbing a WebSocket needs. It's a fine answer where WebSockets are blocked, for example behind some corporate proxies.

GreatWebSockets with move numbers and replay

Approach

Each app opens one WebSocket to a realtime gateway and subscribes to its game's channel. After a commit, the API publishes the move, and the gateway pushes it to both players within milliseconds. Every message carries its move number. On reconnect, the app sends the last move number it saw, and the gateway reads anything newer from Postgres before going live again.

Challenges

About 100,000 sockets need a few dedicated gateway machines, and a deploy has to drain them. The channel can drop a message, so the app watches move numbers: a jump from 7 to 9 means it missed one and asks for it. Postgres stays the truth, and the push is only a fast path.

app -> gateway resume game g1 after move 41
gateway -> app move 42 player 2 fires B7: miss
gateway -> app move 43 player 1 fires D4: hit
gateway -> app live from here

Server-sent events would work too, since moves only flow one way, and shots still go over plain HTTP. WebSockets win slightly here because a game might later add chat or rematch prompts that flow both ways. The real-time updates lesson compares the three options in general.

How do we keep each fleet secret?

Battleship is a game of hidden information, and the client runs on the player's machine. Anything the server sends can be read in the browser's developer tools. So the server is the only party that ever knows both fleets. It answers each shot with miss, hit or sunk and nothing more.

1

Send each player only what they may see

A player's view of the game is their own fleet plus every shot fired so far, with its result. The response is built per player on the server. Sending the full game and hiding half of it in the interface leaks every ship to anyone who opens the network tab.

2

Check who is asking on every call

The game id in the URL says which game, never who you are. Take the player from the signed-in session and check they belong to this game. Otherwise anyone can change a number in the URL and read or play someone else's game. Security folks call that broken access control, and it tops the OWASP list of web risks.

3

Validate every move on the server

Bounds, turn, repeated cells and fleet placement are all checked by the API, using the same rules as the coding round. A modified client that fires twice, fires off the grid or places no ships gets a rejection.

4

Rate limit per player

A script firing hundreds of shots a second gets nothing from the game rules, but it does load the database. Cap shots per player at a few a second and reject the rest before they reach a transaction.

The GitHub angle
Senior loops at GitHub have asked security questions straight after the code. Here the obvious probe is "can player one see player two's ships?" Answer it before it's asked. Per-player views and session checks on every call are what they're looking for.

What happens when a player disappears, or we deploy?

Players leave games all the time. They close the laptop, lose signal, or just stop. In one process you'd never notice. Online, an abandoned game sits in play forever and the other player stares at "waiting for opponent". Give every turn a deadline, say 60 seconds, stored on the game row. The Turn timer runs every few seconds and looks for games in play whose deadline has passed, using an index on that column. For each one, it passes the turn. After three missed turns in a row it ends the game as a forfeit. Its write uses the same turn and move-count condition as a shot. A shot that commits in the last second wins the race, and the timer's write then updates zero rows and does nothing. Clean up the rest in the background. Games that never got a second player expire after a day. Finished games stay for history, or move to cheaper storage after a few months.

Deploys touch the two stateless tiers differently. Game API machines roll one at a time, finishing their in-flight requests first, and nobody notices. Gateway machines hold connections, so a deploy cuts them. Tell connected apps to reconnect, then close. Each app waits a random second or two before reconnecting so 20,000 sockets don't arrive at once, then resumes from its last move number. A shot sent during the gap is just an HTTP call to a different machine. Database changes need the same care. Add new columns before code uses them and drop old ones only after no running code reads them. That way a rolling deploy with old and new code side by side never breaks a live game.

Where would performance problems show up?

The game logic isn't the bottleneck. The coding round's per-ship hit counters already resolve a shot in constant time, and a board has at most 100 cells. Time goes to what surrounds it, mostly the database round trip and the pushes out to players.

  • Database connections. Each shot holds a connection for a few milliseconds. Put a pooler such as PgBouncer in front so hundreds of API processes share a small, fixed set.
  • Load on the primary. At 10,000 shots a second, every shot is a write. Keep the transaction tiny: one insert, one conditional update, nothing else.
  • Reads on reconnect. A gateway restart sends thousands of catch-up reads at once. Index shots by game and move number so each read is one short range scan.
  • The shots table's growth. About 3.5 million games a day at 100 shots each is 350 million rows. Partition by day so old data drops cheaply.
  • Hot spots. No single game is busy, so there's no hot key to worry about. Load spreads evenly by game id.

The daily figure comes from the earlier numbers. If the day averages 20,000 live games and each lasts 500 seconds, that's 20,000 times 86,400 divided by 500, about 3.5 million games. Caching deserves a direct answer, because it will come up. Caching the game state buys little, since every shot changes it and the shooter needs the committed version. Cache what's read often and changes rarely. Player names and avatars are good examples, and so is the finished-game summary shown on a profile page. The caching fundamentals lesson covers when a cache helps in general.

The GitHub angle
Older GitHub rounds asked about caching and API endpoints inside a code review, and how to scale a client sending requests to a server (both 2022). The habit carries over: say what not to cache and why. "The game changes every shot, so I'd cache profiles instead" is a stronger answer than a cache drawn in front of everything.

What do we monitor in production?

Start with what a player would notice, then work inward. A player notices a slow shot, a move that never shows up, or a game stuck on "waiting". Each of those gets a number on the dashboard and an alert. Track shot latency at the median and the 99th percentile, against the 200 ms target. Track the time from a commit to the opponent's push, which should stay under a second. Count stuck games, meaning games in play whose last move is older than two turn deadlines; that number should be zero, since the timer is supposed to clear them. Put error rates by reason next to these. A trickle of "not your turn" and "already fired" is normal. A spike usually means a client bug or a script.

Then the machinery. Watch open WebSocket connections per gateway and the reconnect rate, which jumps when a gateway is unhealthy. On the database side, watch connection pool waits, transaction time and replica lag. For the timer, watch how far behind it runs. Tag every log line with the game id and move number, so one search shows a disputed game shot by shot. The shots table backs that up, since it records every move with its result.

The GitHub angle
GitHub has asked "What makes a system production-ready?" in past loops (2021, 2022). Have a short list ready for this game: alerts on what players feel, a rollback that takes minutes, a load test at twice the expected peak, and deploys that don't drop games. Naming those concretely shows you've run a live service.

The monitoring and observability toolbox page covers metrics, logs and traces in general.

Practice the core in code

The design shrinks to one class worth coding. It keeps many games at once and takes shots tagged with a move id. A returning player can ask for the moves they missed. The database and the network are gone. The rules that decide correctness stay: a retried move id returns its first result, and a rejected shot leaves no trace, so move numbers never skip.

1

Battleship Game Server With Retried Shots and Move Replay

Medium
Problem
Build a GameServer that runs many two-player Battleship games on a 10 by 10 grid, rows and columns 0 to 9. create(game_id, fleet1, fleet2) starts a game and returns true, or false if the id is taken. A fleet is a list of ships, and a ship is a list of [row, col] cells. Fleets are valid, non-empty and don't overlap. Player 1 shoots first.

fire(game_id, player, move_id, row, col) shoots at the other player's fleet. Check in this order. Return "no game" for an unknown game. If move_id was already accepted in this game, return its stored result and change nothing. Then return "game over" if someone has won, "not your turn", "out of bounds", or "already fired" if this player shot that cell before. None of these rejections is recorded.

Otherwise the shot is accepted: "miss", "hit", "sunk" when it hits a ship's last cell, or "player wins" when it sinks the last ship. It gets the next move number, starting at 1 in each game, and the turn passes to the other player.

moves(game_id, after) returns every accepted move with a move number greater than after, as [move_number, player, row, col, result], in order. It returns an empty list for an unknown game.

Input encoding. A test case is a JSON array of operations. The first entry is ["GameServer", []] and each later entry is [method, [args]]. The expected array holds each operation's return, with null for the constructor.
  1. GameServer()
  2. create("g1", [[[0, 0], [0, 1]]], [[[5, 5]]])→ true
  3. fire("g1", 1, "a1", 3, 3)→ "miss"
  4. fire("g1", 1, "a1", 3, 3)→ "miss"
  5. fire("g1", 1, "a2", 4, 4)→ "not your turn"
  6. moves("g1", 0)→ [[1,1,3,3,"miss"]]

The second call is a retry of move a1 after a timeout. It gets the stored result and adds no move. The next new shot from player 1 is out of turn and leaves no trace.

How this uses the pattern

Keep one record per game. It holds each fleet as a map from cell to ship index with hit counts, plus the cells fired at. Add the turn, the winner, the move list and a map from move id to result.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Battleship Game Server With Retried Shots and Move Replay

Loading...
Click "Run" to execute your code
The GitHub angle
This is the conditional write and the idempotent move id from the design, small enough to run. Order matters most. The move id lookup comes before the turn check, because a retried shot arrives after the turn has already passed. Check the turn first and the retry gets "not your turn" for a shot that landed. State that order before you code.
Take it further
Bring the rest of the design back in. Add an expected move number to fire, so a client acting on stale state is rejected, which is the version check from the conditional write. Add a turn deadline and a tick(now) method that passes stalled turns. Then say how the maps become the games, fleets and shots tables.

Follow-ups to be ready for

Matching strangers. Add a lobby queue: a player asks for a game, and a matcher pairs the two who have waited longest, creates the game and tells both. Keep it outside the game path, so a slow matcher never delays a shot.

Playing against the computer. The bot is just another player that calls the same fire endpoint. Run it as a worker that listens for "your turn" on the bot's games. It gets no special access to the board, so the server rules still protect the game.

Players in many countries. A game's two players might be far apart. Keep each game in one region, ideally the one its creator is closest to, and accept an extra 100 ms or so for the far player. Games never span regions, so the data splits cleanly by game.

Disputes and replays. The shots table already holds every move in order with its result. A replay viewer reads it back, and a support engineer can answer "I hit that ship!" by looking up the move.

What is expected at each level

Mid-level (SWE II and III)

Mid-level loops often have no design round at all; one 2026 SWE II loop with Battleship had two technical rounds and no design. If this comes up, aim for breadth, about 80/20. You move state out of memory into a database with the server as the only judge. Then you explain how the opponent hears about a shot. Get the turn race right when prompted. The bar: a complete skeleton you can explain, with the shot as a database write and server-side rule checks.

Senior

Senior is where this follow-up came up. Go about 60/40, breadth to depth. You find the race and the retry problem yourself, and you reach the conditional write with a move id without being led. Defend Postgres over Redis for the record, and push over polling with numbers. Bring up hidden fleets and stalled games before the interviewer does. The bar: a shot that counts exactly once under retries and races, and a clear list of what you'd watch in production.

Staff and above

Staff loops at GitHub include a system design interview. If you get this one, go 40/60. Lead the conversation and spend your depth on operations. Cover deploys that never drop a game and schema changes with old and new code running side by side. Add a load test plan, and say when you'd split the database by game id. Talk about cost too. Gateway machines and database headroom are the main bills, and you should say which one grows first. The bar: you drive the whole hour, and the interviewer redirects rather than rescues.

Common questions

Does the GitHub system design interview ask Battleship?

It came up as a follow-up inside the Battleship coding round in a November 2026 senior loop, after the object-oriented part. Senior and staff loops usually include a design conversation, either a standalone round or questions folded into pairing.

What does a GitHub senior software engineer interview ask about production?

Expect practical questions about code you just wrote or reviewed. How would it scale, what would you cache, how would you secure it, and what makes it production-ready? Each has come up in GitHub rounds over the years, and this lesson works all four for Battleship.

How should I practice?

Build the game from the coding lesson on a timer, then explain this design out loud in 15 minutes using your own classes. Finish with the practice problem above, since it covers the retry and turn rules most answers get wrong.

Key Takeaways

  • ✓Move the game out of server memory into Postgres: a game row, two fleets and an append-only list of shots.
  • ✓Make each shot one conditional write on turn and move count, and look up the move id first.
  • ✓Push moves over WebSockets with move numbers, so a returning player replays exactly what they missed.
  • ✓Send each player only their own view, give turns deadlines, and alert on what players feel.
GitHub interview guide

Know what GitHub asks before you walk in.

20 coding · 3 system design · 31 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

The System Design InterviewHad your GitHub interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.