Nicholas Forlivesi  •  Elena Sarti
abstract

ScalaJack started as a Blackjack game for a single terminal, written in Scala 3 with the scores computed by a Prolog theory. In this project we turned it into a distributed system in which players log in from their own command-line client and share tables with other players. The system is made of a lobby that handles accounts and the directory of the tables, of a PostgreSQL database that stores users and their balances and of a set of table nodes, each of which plays one table and is paired with a backup. Tables are replicated with a passive primary-backup scheme: every change of state is stored on the backup before any player can see its effects, so that a backup taking over continues the hand exactly where the players saw it. When the two replicas lose contact with each other, the lobby acts as an arbiter that decides which of them may go on and the epochs it grants work as fencing tokens that stop a replaced node from speaking again. Between consistency and availability the tables choose consistency, so a table that cannot replicate a move pauses instead of risking two diverging hands or money that appears or disappears. Clients detect a silent table by themselves, ask the lobby where their table is now and sit down again in the same seat, so a crash of the primary is perceived as a pause of a few seconds. The whole system is deployed with Docker Compose on a single machine and the lobby starts new tables through the Docker API when the existing ones are full.