Case study · Spring Boot + Android · 2019–2022
Tic-tac-toe, rebuilt as a modern Android game with a real online mode. Pick a nickname, invite anyone from the live lobby and play in real time, while my own Spring Boot service runs every match in parallel, with no cap on how many.


A complete tic-tac-toe game for Android with three ways to play, a custom animation library, and xo-api, a small Spring Boot service on my home server that runs the online lobby and every live match side by side.
A live lobby, invites with a countdown, real-time moves and rematches against anyone, from any phone, synced in about half a second.
A stateless Spring Boot API. Every match is its own row in MariaDB, so matches never wait for each other. Tested with 1,000 at once.
An AI with three difficulty levels, or two players on one phone. Matches of 1 to 7 rounds and win statistics in a Room database.
Everyone knows tic-tac-toe. Most apps for it feel like a school exercise: a plain grid, a hard-coded opponent, and nobody to play with.
Neo XO treats it as a real game. It has a soft, modern look, motion on every screen, an AI with three personalities, a match format with a score, and online play against anyone in the lobby. It is published on Google Play in English and Romanian, and it shows no ads.
This board plays exactly like the single-player mode in the app. The AI uses the same rules for each level, thinks for the same 1 second, and a coin toss decides who opens each round. You are X. Change the level or the match length to start a new match, and watch your statistics build up.
AI is thinking
OVERALL STATS MEDIUM
WIN RATE 0%
The AI does not search the game tree. Before each move it scans the 8 lines of the board, the three rows, three columns and two diagonals, and answers three questions: can I win now, must I block a line where X already has two, and is there a line I can build on?
The level decides how it uses the answers. That keeps it fast and easy to tune, and it makes each level feel different: Easy makes human mistakes, Medium never misses a threat, and Hard also plans ahead.

SpPlayActivity · AI move, condensed// every line is scanned first: can the AI win, must it block, can it build?
switch (matchDifficulty) {
case DIFFICULTY_EASY:
if (canWin) putO(OlistNo, OelemNo);
else if (isCheck) {
if (getNoOfSigns() < 4) putO(listNo, elemNo);
else if (rand.nextInt(3) < 2) putRandom();
else putO(listNo, elemNo);
} else putRandom();
break;
case DIFFICULTY_MEDIUM:
if (canWin) putO(OlistNo, OelemNo);
else if (isCheck) putO(listNo, elemNo);
else putRandom();
break;
case DIFFICULTY_HARD:
if (canWin) putO(OlistNo, OelemNo);
else if (isCheck) putO(listNo, elemNo);
else if (canMoveSmart) putO(smartOlistNo, smartOelemNo);
else putRandom();
break;
}
EASY
Takes a win when it sees one. It blocks early threats, but once the board fills up it blocks only 1 time in 3 and plays a random cell otherwise.
MEDIUM
Wins if it can and always blocks. Otherwise it plays a random cell, so it is solid but has no plan of its own.
HARD
Wins, blocks, and otherwise builds: it adds a second O to a line that holds one O and no X, setting up its next win.
Online play runs on xo-api, a Spring Boot REST service I wrote for the game. It runs in Docker on my home server, behind a Traefik reverse proxy with automatic HTTPS. The phones never talk to each other: every invite and every move is a request to the API, stored in MariaDB, and read back by the other player.
Both players talk only to xo-api. The database is the single source of truth for every lobby and match
SPRING BOOT
No sessions, sockets or game threads. The service keeps nothing in memory, so a restart never loses a match, and many matches run side by side.
MARIADB
Two entities, XoPlayer and XoMatch, with CRUD repositories. Every write runs in a @Transactional service method.
SCHEDULER
A @Scheduled job runs every 5 minutes and deletes players and matches that have not been updated for 5 minutes or more.
ACTUATOR
Spring Boot Actuator exposes the health endpoint. The app calls it first and shows the server as Online or Offline.
2 controllers · 12 endpoints · base path /xo-api · plus /actuator/health
/actuator/healthIs the service up? Shown as Online or Offline/lobby/playersEveryone in the lobby, with status and opponent/lobby/players/{name}One player: status checks and invites/lobby/players/namelistJust the nicknames/lobby/players/post/jsonJoin, or change a status. The date is set to now/lobby/players/{name}Leave the lobby/matches/idListIds in use, to pick a free one/matches/{id}The board, the turn and the status/matches/post/jsonCreate a match or save a move/matches/{id}Remove a finished matchThe online screen calls the health endpoint and shows the server as Online or Offline.
Names are upper-cased and must be unique. In the recording MARIA is taken, so the app says "Name already taken!".
The player is posted as FREE. Players who are already in a match are hidden, so the list only shows people you can invite.
Three loops poll the server. When ALEX joins, he appears within a second and the count goes from 5 to 6.
1000 MS
Refreshed every 1 s. Each row has an INVITE pill, and a pulsing ring behind the list shows that the lobby is live.
500 MS
Polled every 500 ms. This is how the sender learns that an invite was accepted and which match to open.
200 MS
Checked every 200 ms, so the invite dialog opens almost at once. After a decline, new invites are paused for 14 s.
TIMEOUT
After 5 minutes without an update, the app returns to the menu with "Disconnected due to inactivity", and the server cleans up the row.
Starting a match takes two phones, one server and no direct connection. The handshake is a short conversation through the lobby table: each player writes a status, and the other one reads it on its next poll. Both sides show a 10 second countdown, and anything other than an accept returns both players to FREE.
TWO PHONES · ONE INVITE
Recorded on two phones against xo-api. EDUARD taps Invite, CRISTINA's phone shows the invite with its countdown about a second later, she accepts, and both phones open the same match.
The invitation handshake. Every step is a plain HTTP call, and the lobby table holds the state in between
The lobby statuses. A decline, a cancel or the 10 second timeout sends both players back to FREE
The receiver does the heavy lifting. Before accepting, it re-reads the sender to make sure the invite is still open, so a cancelled or expired invite never starts a match.
It then picks the lowest free match id, creates the match with a random first turn, and writes START_MATCH-7-B to the sender: the match id and who plays first, packed into one status. The sender sees it within 500 ms, and both phones open the same match.
InviteFromDialog · accepting an inviteprivate void acceptInvite() {
int matchId = generateMatchId();
XoMatch xoMatch = new XoMatch(myName, playerWhoSentName);
xoMatch.setId(matchId);
xoMatch.setRandomFirstTurn();
xoMatch.setStatus(MATCH_STATUS_PLAYING);
// the sender is waiting for: START_MATCH-{id}-{firstTurn}
setOpponentStatusToStartMatch(matchId, xoMatch.getTurn());
startMpOnlinePlayActivity(xoMatch);
}
public int generateMatchId() {
List<String> idList = getIdList();
int id = 1;
while (idList.contains(String.valueOf(id))) {
id++;
}
return id;
}
A match is a single row in the matches table: the two players, whose turn it is, the nine cells b1 to b9, a status and the rematch flags. Only the player whose turn it is can write, which keeps the two phones from overwriting each other. While you wait, the app polls the match every 500 ms, and it checks the match status every 700 ms to notice a disconnect.
LIVE MATCH · SYNCED
A real online round. Each move shows up on the other phone within about half a second, and both phones work out the gold winning line and the score from the same board.
MpOnlinePlayActivity · canPress, condensedprivate boolean canPress(View view) {
boolean myTurn = myName.equals(xoMatch.getTurn());
boolean empty = ((Button) view).getText().toString().isEmpty();
if (myTurn && empty && !putSignTimerIsOn) {
// one move per 500 ms, even with a double tap
putSignTimerIsOn = true;
mHandler.postDelayed(() -> putSignTimerIsOn = false, 500);
return true;
}
return false;
}
XoMatchController · POST /matches/post/json@PostMapping("/post/json")
public void addMatchJson(@RequestBody String xoMatchJson) {
XoMatch xoMatch = mapper.readValue(xoMatchJson, XoMatch.class);
xoMatch.setDate(LocalDateTime.now().toString());
// a move carries no status: keep the one already stored
if (StringUtils.isEmpty(xoMatch.getStatus())
|| "NULL".equalsIgnoreCase(xoMatch.getStatus())) {
XoMatch current = xoMatchService.getMatchById(xoMatch.getId());
xoMatch.setStatus(current.getStatus());
}
xoMatchService.persist(xoMatch);
}
MOVES
A tap counts only on your turn, on an empty cell, and not within 500 ms of the last one. The move is posted and the turn passes over.
ROUNDS
The first turn of the match is random. After that, the opening move alternates every round, so nobody keeps the advantage.
REMATCH
Each player sets their own rematch flag. The other one sees "requested a rematch" and an Accept button. When both flags are set, a new match starts.
STATUS
Leaving sets the status to DISCONNECTED. The other phone shows "left the match", deletes the match and goes back to the lobby.
MATCH END · REMATCH
The end of a first-to-3 match. Each phone shows its own result, CRISTINA asks for a rematch, EDUARD sees "requested a rematch" and a green Accept, and a new match starts on both phones.
The lobby is not one shared game room. Every match is an independent row, the service keeps nothing in memory, and no match ever touches another match's row. So matches never wait for each other, and nothing in the code limits how many run at once: the only limits are the server's threads and database connections.
You can see it in the recordings. While EDUARD and CRISTINA play, six other matches are running on the same server, and those players are hidden from the lobby until their match ends.
Every match is its own row. The service holds no match in memory, so matches never wait for each other, and nothing in the code caps how many run at once
Two simulated phones per match, polling exactly like the app: the board every 500 ms, the status every 700 ms, and a move on every turn. 60 seconds per run.
| Matches | Phones | Requests / s | Median | p95 | Errors | Lost moves |
|---|---|---|---|---|---|---|
| 100 | 200 | 648 | 1.0 ms | 3.8 ms | 0 | 0 |
| 250 | 500 | 1,624 | 0.6 ms | 2.9 ms | 0 | 0 |
| 500 | 1,000 | 3,263 | 0.5 ms | 1.3 ms | 0 | 0 |
| 1,000 | 2,000 | 6,307 | 9.6 ms | 54 ms | 0 | 0 |
Run on one laptop against a local copy of xo-api with an embedded H2 database in place of MariaDB, so it shows how the design behaves, not production numbers. At 1,000 matches the single-threaded test client was the limit: the API used about 1.6 of 14 CPU cores. A first run at that size had 246 client time-outs (0.07%); the repeat had none. After every run, each phone checked that all of its moves were still on the board.
STATELESS
No sessions, sockets or game threads. Each request reads or writes one row and returns, so any of Tomcat's 200 worker threads can serve any match.
ISOLATION
A move writes only its own match row, so parallel matches never lock each other. Writes are short @Transactional calls over a pool of 10 connections.
CONSISTENCY
Inside a match, only the player whose turn it is may write. The server keeps the stored status, so a late move cannot undo a match end.
SCALE OUT
Because nothing lives in memory, more xo-api containers could run behind Traefik against the same database without changing the app.
Known limit: the phone that accepts an invite picks the lowest free match id. If two invites are accepted in the same instant, both phones could pick the same id. It never showed up in the load test, which creates its matches up front, and the fix is to let the database generate the id.
The whole online game fits in two tables. Every write refreshes the date column, which is what the cleanup job and the inactivity timeout both read.
MariaDB · mapped with Spring Data JPA · schema kept in sync by Hibernate
lobbyXoPlayernamevarchar'EDUARD'statusvarchar'PLAYING'opponentvarchar'ANA'datevarchar'…T18:42:07'matchesXoMatchidint7player1varchar'EDUARD'player2varchar'ANA'turnvarchar'ANA'statusvarchar'PLAYING'b1 … b9varchar'X' · 'O' · ''rematch1, rematch2varchar'REQUESTED'datevarchar'…T18:43:12'/xo-api/matches/7{
"id": 7,
"player1": "EDUARD", "player2": "ANA",
"turn": "ANA", "status": "PLAYING",
"b1": "X", "b2": "", "b3": "O",
"b4": "", "b5": "X", "b6": "",
"b7": "O", "b8": "", "b9": "",
"rematch1": "", "rematch2": "",
"date": "2022-05-14T18:43:12.519"
}
Moves are posted without a status. The server fills it in from the stored row, so a move can never undo a MATCH_END or DISCONNECTED written by the other phone.
Old rows are not a problem either. The scheduled cleanup runs every 5 minutes and removes anything that has been quiet for 5 minutes, which also covers phones that lost their connection without saying goodbye.
XoCleanupService · condensed@Scheduled(cron = "0 */5 * ? * *")
public void startMatchCleanup() {
LocalDateTime now = LocalDateTime.now();
xoMatchService.getMatches().forEach(match -> {
LocalDateTime entryDate = LocalDateTime.parse(match.getDate());
if (entryDate.until(now, ChronoUnit.MINUTES) >= 5) {
xoMatchService.deleteById(match.getId());
}
});
}
Every movement in the game comes from MyAnim, a small animation library I wrote on top of Android's ObjectAnimator. It has around 20 ready-made effects: pop, press, buzz, slide, zoom, fade, colour changes, a progress bar and a number count-down.
The recording shows the menu as it really runs: the logo pops in, the background slowly zooms, buttons shrink to 90% when pressed, and each screen slides its buttons in. On the board, signs zoom in with an overshoot, and a bad nickname makes the field buzz.
MyAnim · pop, condensedpublic static void pop(View view) {
ObjectAnimator goUp = ObjectAnimator.ofPropertyValuesHolder(view,
PropertyValuesHolder.ofFloat(View.SCALE_X, 1.0f, 1.1f),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.0f, 1.1f));
goUp.setDuration(500);
ObjectAnimator goDown = ObjectAnimator.ofPropertyValuesHolder(view,
PropertyValuesHolder.ofFloat(View.SCALE_X, 1.1f, 1.0f),
PropertyValuesHolder.ofFloat(View.SCALE_Y, 1.1f, 1.0f));
goDown.setDuration(500);
goDown.setStartDelay(500);
goUp.start();
goDown.start();
}
SCALE
pop grows a view to 110% and back to call for attention, like a rematch Accept. press dips a button to 90% and back.
TRANSLATE
Views slide in on X, Y or Z, and buzz shakes a view sideways to say no, with or without a rotation.
COLOUR
An ArgbEvaluator blends backgrounds and text colours, and a TransitionDrawable cross-fades button backgrounds.
TIMING
Each effect takes an interpolator: accelerate, decelerate, overshoot or anticipate, for a natural feel.
The look is soft and bright: a pastel pink and blue background, rounded blue board lines, red X and blue O, and gold for the winning line. Text uses the geometric Moon typeface. The app runs in portrait on Android 8.0 and newer.
MENU
Singleplayer or Multiplayer, over a background that zooms in when the app opens.
AI
Easy, Medium or Hard, and a slider for a match length of 1 to 7.
STATS
Win rate, wins, matches and losses for each level, stored in Room.
LOCAL
Two friends, one phone. X and O take turns, and the score keeps count.
CLIENT
Java 17, target SDK 34. 7 activities and 13 dialogs, with OkHttp for the network and Handler loops for polling.
SERVER
Spring Boot, Spring Data JPA, Actuator and Lombok on Java 8, packaged as a jar in a Docker container.
STORAGE
One table holds matches, wins and losses for each level. The StatsDialog turns them into win rates.
I18N
Every string is in English and Romanian, so the store listing is "X si 0 Online" in Romania.
A published game with three modes, an AI with three levels, local statistics, and live online matches on my own backend, any number of them in parallel. The server holds no state in memory, cleans up after itself, handled 1,000 simultaneous matches in a local load test, and has run in Docker next to this website. Version 3.0 removed all ads.
Replace polling with WebSockets and STOMP, validate moves and pick match ids on the server, add optimistic locking to the match row, move xo-api to Spring Boot 3, and add a minimax level that never loses.