RE flagvsflag

John Christopher McAlpine
3 min readJun 3, 2017

Flag vs. Flag is (was) a viral website that where users can vote on their favourite flags. While it’s an extremely cool site, I think that there’s definitely room for improvement, mostly in how flags are ranked. The current Flag vs. Flag voting system works like this:

  1. The site selects two flags from its database at random and sends them to the user for consideration.
  2. The winning flag gets one point, the losing flag gets nothing (Flag vs. Flag also logs the user’s IP address to help detect botnets).
  3. Flags are sorted according to raw score.

This system is fine. However, there are a few issues that appear when it’s deployed and used at scale.

First, the system is not impervious to brigades. One may notice from the ranking that populous countries with a lot of internet users tend to place slightly above where they should be, which is a bit unfair. Also, the totally random selection of flags allows for very boring matchups, e.g.

This isn’t ideal, because we shouldn’t need to tell the site that Belize clearly has the better flag (I mean come on, look at how many more things it’s got!). Ideally, we’d only see matchups between two really good flags

Say what you will about the British Empire, but that whole “crowbar our flag into the upper-left corner and do whatever with the rest” thing really works on just about every level

or two really bad flags

Ugh, come on guys, you do know that brown is a colour, right?

which means that we can’t just go with random selection any more, at least not for most comparisons. What this really turns out to be is a matchmaking problem: how do we generate meaningful matchups of similarly visually appealing flags?

In addition, because this is a matchmaking problem it’s no longer ideal to simply rank elements based on a raw score. There’s a far more robust way to attack this problem:

Associate each flag with a ranking score, a representation of how “good” the flag tends to be. A flag’s ranking score would increase more for winning against a flag with a high ranking score. Matchings should be selected based on flags with similar ranking scores with some random noise thrown in to help give flags with extreme ranking scores a chance to climb/fall into their rightful places more quickly. I have no experience with this sort of algorithm (except for all the DotA that I played in high school), but it would probably be quite simple to implement, improve, and analyze.

Implementation

The server is written in Go, but a ton of the work is actually done by PostgreSQL (e.g. the complicated scheduler logic is almost entirely done on the database). You can find the source here. I used SASS and Pure.CSS for the client.

Flag images are delivered via CloudFront, and the service is hosted with Docker Cloud and Amazon EC2, with the database on Amazon RDS. The site is currently live at flagvsflag.io.

--

--