Haskell at Front Row

I wrote this post originally for the Commercial Haskell SIG

The mission

Front Row Education was founded to change the way math education is done in a modern day classroom. In the web universe we have all sorts of great tools for tracking, analyzing and incentivising user behavior: complex analytics, rich data visualizations, a/b testing, studying usage patterns over time, cohort analysis, gamification etc. We figured: instead of using the above to have granny click on more ads, let’s make these powerful techniques available to teachers, parents and school administrators to make math education more engaging and effective.

Front Row allows schools to track student progress over time, identify areas of struggle, learn how to address them, all the while encouraging more quality practice. Learning math this way becomes a interactive and compelling experience, providing immediate feedback and adjusting content with every answer. As students practice, they generate rich data that school staff uses to continuously course-correct and fill in the gaps.

Numerous experiments from past years show that making Front Row a regular part of a math classroom leads to improved conceptual understanding, a lower rate of students falling behind, and improved scores on state tests. As of today Front Row helps over a million students in their regular math practice, and has been used in over 30% of US K-8 schools.

Our journey to Haskell

As of today Front Row uses Haskell for anything that needs to run on a server machine that is more complex than a 20 line ruby script. This includes most web services, cron-driven mailers, command-line support tools, applications for processing and validating content created by our teachers and more. We’ve been using Haskell actively in  production since 2014.

At the time of the switch we were already familiar with the functional programming world. The central piece to the Front Row system is the JSON API used by both the student and teacher web experiences. I wrote the first version of the API in 2013 in Clojure on top of the Ring/Compojure micro-framework. At the time I didn’t have plans for the API to grow to serve the kind of size and traffic we see today: it was mostly a way for me to really dive into functional programming and understand design challenges that other popular frameworks had to come across.

Building your own framework is a fantastic learning experience, but it is also a significant commitment: without investing a ton of time and effort into the framework, you’ll end up with something very bare-bones and hard to turn it into a production quality, fully-featured application. It takes innumerable iterations to make a framework extensible, modular and well maintained with a team of 1-3 developers, busy with dozens other tasks that a fast-moving startup demands.

Clojure at the time didn’t offer any alternatives as far as web frameworks were concerned, and we were already starting to see the inherent critical weakness behind building large modular systems in dynamically typed languages: refactoring is a serious pain and something you will avoid at all costs because it’s hard to ensure you’re not breaking anything. It’s not that bad if you have ONE codebase that doesn’t have dependencies, but once you get into two digits you’re in for a bad time.

Switching to Haskell and the Yesod framework seemed like a natural step forward: a strongly typed, purely functional, highly expressive language that would finally allow refactoring and moving fast to be painless. On top of it, a beautifully designed, extensible web framework with years of polish, one of the best high-performance web servers in the industry, extreme attention to type safety, and an all-star team of OSS contributors supporting it.

Moving from Clojure to Haskell didn’t feel like a massive jump: a lot of concepts translate pretty closely, although Haskell offers a much richer vocabulary than just maps and vecs. Monads, type classes, IO etc. eventually clicked, and it was smooth sailing after that.

Advantages of using Haskell

Where does Haskell fit into all of this you say? As the development team of a small early stage edtech startup, we have two main goals:

  1. Iterate as fast as possible on new educational concepts, business model experiments and user feedback. Basically, crank out as much code as possible while keeping the quality bar very high.
  2. Stretch our runway, be conservative with our very limited resources

Haskell fits in pretty well with both of goals.

Static typing

First of all, static typing is essential when it comes to keeping the system always in a working state. Coming from a dynamically typed universe, it’s surprising how much time you can save on writing unit tests, because you are getting more certainty from the compiler: no more null exceptions, no type mismatches in function calls, no more forgetting about dealing with the empty list case etc. A whole class of pesky, incredibly common and banal bugs is eliminated from your work: you now have more bandwidth to worry about implementing user stories instead of obsessing that your application doesn’t blow up due to sloppy oversight.

I still remember one of my biggest Haskell/Yesod “aha” moments: not only does Yesod make sure that routes in your HTML are type-safe, but even image files linked in < img > tags are verified to exist on disk by the compiler. No .jpg, no build, it’s that simple. It’s a level of guarantee that dramatically increases your confidence in the code at barely any cost.


Modularity is another big one. We have a central module at the bottom of every one of our web applications, APIs, tools and cron binaries. This module wraps the database entities and the SQL logic necessary to access them. It also provides a lot of common shared functionality that should not be implemented more than once. Since the schema changes very aggressively, we need a way to make sure our applications are updated ASAP, we can’t wait for things to blow up in production. Updating our entity definitions in that one module prevents every application built on top of it from compiling again until the change is dealt with.

No more API call mismatches, no more using an old schema, no more apps running against an old deprecated version that can lead to breaking the db state. As many others have stated, Haskell is the first language out there that feels like it manages to achieve true modularity: purity and defining what context a function is allowed to run in ensure that a library call can lead to no surprises. Testing side-effect free functions is much simpler than continuously dealing with system state.


Regarding the second point, why would Haskell stretch your runway? Simple. You’re writing fewer bugs, you’re reusing more code, new developers are causing less damage, and you have more room to deal with technical debt before it bites you. Purity and static types allow a team to aggressively refactor the codebase without having to worry that they might have forgotten to update something: a combination of a light layer of spec-style tests and a very picky compiler provide you with most of what you need to make refactoring a non-issue. More refactoring = more long-term productivity, higher team morale, more pride in one’s work. Doing the same with a Ruby is as fun as pulling teeth.

All of the above adds up to needing fewer developers, as less time is spent on maintenance, which ultimately equals a higher chance of your company getting somewhere thanks to the more frequent iterations. The more stuff you try, the more likely you are to find or expand that business mechanic that will carry your business forward.

Trouble in paradise

Things aren’t all perfect though. There are still quirks and plenty of room for improvement in the ecosystem.


Build times, especially once the whole constellation of Yesod and Persistent packages are brought into the mix, are not insignificant. It still takes a good 5-10 min to build our larger web application on our beefiest machines. There are optimizations that can be made in this space which we haven’t adopted yet, such as caching already build object files to avoid having to re-compile them every time, so I’m confident this will be a non-issue in the nearby future, but it’s still worth being aware of. GHC works hard, you need to provide it with enough juice or time to let it do its job.


The testing frameworks out there are still fairly spartan from the developer experience standpoint. If you test Yesod with hspec, the premier BDD library for Haskell, there’s currently no way to insert a bunch of rows into the database during fixtures and pass the results into the individual test cases. You have to wrap each test case in additional
function calls to pull that off, adding more boilerplate to your tests.

Additionally, it’s not possible to find out which one of your specific test cases failed when checking for multiple conditions within the same “it” block. This means that if you need to check the state of the system after an HTTP request, you have no clue which one of the checks failed.

Fortunately the developer(s) behind these libraries are responsive and happy to look into improvements. At the very least they’re glad to point other developers in the right direction towards a PR.

This has in general been my experience with the Haskell community: things aren’t perfect, but folks are always looking for a way to improve the ecosystem and want Haskell to be the best language to develop in. People are trying to carve out their little slice of paradise, and are willing to put in the hard work to make it happen.


Documentation is still not quite there and the initial onboarding of new developers is still rough. There are only so many snippets to Google for, compared to e.g. Ruby and Python. A lot of documentation is very barebones and requires diving straight into the source, which is fine for a proficient Haskeller, but not for an already terrified beginner.

Many times I’ve witnessed senior developers get very frustrated when something wouldn’t compile for hours and they couldn’t find any help to move forward: be prepared to assist them before they get too grumpy. Some projects are better about it than other: Yesod and Persistent have extensive documentation and the FPComplete crew have numerous tutorials out there to help. New books come out once in a while with fresher snippets: the time-tested Real World Haskell is now fairly outdated, but the more recent Beginning Haskell is perfectly relevant. Many channels on IRC are available:
#haskell-beginners, #haskell and #yesod, although sometimes it can take work to get the answer you’re looking for. More than once I heard the comment that documentation seems to be written by wizards for other wizards, and if you’re a lowly initiate, you will have a rough time.

I’ve personally had the privilege to help all of our developers skill up in Haskell and Yesod, and I’ve become a huge believer in the power of having someone more experienced guide you along the way. What took me several months of learning, mostly by myself, now takes our developers a couple of weeks of quality coaching. It took me a while to grok monads, type classes, type families etc., however, properly guided developers can figure it out in a matter of hours. Having a good teacher on your team will speed adoption within the organization immensely.

Strength in numbers

We once experienced a very frustrating issue that got us thinking about our full commitment to Haskell as a company.

When we switched our main API to Yesod (a full rewrite), we almost immediately ran into the issue the API would burn up close to 95% of available CPU on whatever AWS EC2 instance it was hosted on. We upgraded machines, just to see if we could cheat our way out of fixing this by throwing money at the problem, and even with a $600/mo 16 core box, the API still managed to flood all of the available cores with barely any traffic hitting it. I personally spent a good week banging my head against it: was it resource contention? Was it a really big oversight in one of my handlers? Was it misconfiguration? Was it something about the EC2 environment? Why doesn’t this reproducing AT ALL under profiling? Was it our database connection pooling? I threw a lot of screenshots and code samples at the community both on Google Groups and IRC: nobody else had ever seen anything like it. Uh oh.. All the while customer support requests are pouring in,
teachers are aggravated, the team is looking at the devs and “their latest shiny toy”,  tapping their collective foot.

This is the part where picking exotic tooling for your stack can be a dangerous beast: “given enough eyeballs, all bugs are shallow”, and when only a dozen teams out there are using your libraries at your scale, you are on your own when it comes to fixing issues. With Rails, there’s enough volume of developers that there will be enough projects of every scale to burn-in your tool of choice. That’s simply not the case with Haskell’s usage numbers.

What this means is that if you’re planning to bet the farm on Haskell, you need to be ready and comfortable with the idea that you might have to get your hands dirty, might be the first person to figure out a solution to the problem you’re seeing. This requirement is pretty much non-existent in .NET / ruby / python at al. Start small, start simple, let the tooling grow on you as you gain experience. Start with tools that aren’t mission critical until you’re more confident.


It bears mentioning that the above concerns are being actively addressed by the community and the state of things is rapidly improving:

  • Cabal, the Haskell package manager, was a real pain to work with just a few years ago and “cabal hell” is still part of Haskell vernacular. However, with sandboxes and consistent version snapshots provided by FPComplete as Stackage LTS, that problem has been mostly resolved.
  • Build times are slow, but the community is coming up with improvements such as halcyon that should alleviate things considerably.
  • Docs have gotten dramatically better over the past couple of years. There’s been a big push towards keeping fresh, community-maintained, easy-to-follow and beginner-friendly instructions such as those provided by Chris Allen’s Learn
    . We now even have IRC channels tailored specifically for beginners, e.g. #haskell-beginners . Today newcomers become more productive much faster than they did a few years ago.
  • The community has been recently doing a better job at outreach and we’ve seen many new developers come make Haskell a permanent part of their toolbox. With more participants, tools get more fully-featured and more maintained.


It’s a very exciting time in the history of computing to jump on the Haskell train. Yes, the community is tiny and one might get little hand-holding compared to more popular ecosystems, however Haskell offers obvious benefits to software teams who can power through the initial pain period.

Today Haskell offers some of the best tools around for delivering quality software quickly and reliably, minimizing maintenance cost while maximizing developer enjoyment. To me Haskell is that dream of “developer happiness” that we were promised many years ago by the Ruby community: I can write beautiful, short, expressive and readable code that will perform phenomenally and stand the test of time and continuous change. What more can I ask for?

To find out more about Front Row, visit us at https://www.frontrowed.com. You can also follow me at https://twitter.com/alex_kurilin

Shameless plug: we’re hiring. Currently looking for a Founding Systems Engineer with DevOps focus.

Haskell at Front Row

Upgrading Yesod 1.2 -> 1.4

I’ve recently had to quickly upgrade Yesod 1.2 web application from version 1.2 to 1.4. I was looking for resources on how to do this and couldn’t find anything beyond Announcing Yesod 1.4 and Persistent 2.1 Released. This post should be useful if you’re in a similar situation and your app is backed by PostgreSQL, even though it should work just about the same for any other SQL backend.The transition was actually pretty simple, you have to take care of the following steps:

Update the libraries

Installing Yesod 1.4 through hackage is even more of a pain that before. It’s doable, and I have done that before, but I strongly recommend using Stackage Server. Go with an exclusive snapshot to avoid headaches and having to set constraints. It completely takes care of cabal hell as long as your dependencies aren’t highly exotic. Even then there are ways to work around it, but that’s for another post.

Once yoru cabal is wired against Stackage, remove version constraints from all of the packages in your .cabal file, as those will be decided for you by the Stackage snapshot.

Update Foundation.hs

-- replace this
import Database.Persist.Sql (SqlPersistT)
-- with this
import Database.Persist.Sql (SqlBackend)


-- replace this
giveUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")
-- with this
withUrlRenderer $(hamletFile "templates/default-layout-wrapper.hamlet")

Add the following after all of the implementations of instance YesodAuth:

instance YesodAuthPersist App


-- replace this
share [mkPersist sqlOnlySettings, mkMigrate "migrateAll"]
-- with this
share [mkPersist sqlSettings, mkMigrate "migrateAll"]

Update SQL entities

Love timestamptz in Postgres? ZonedTime SQL type is gone in Persistent 2.1: it’s now officially replaced with UTCTime which was already available before. If you actually need to know the TZ of a certain timestamp, you’re going to need a custom solution, Persistent isn’t going to do this out of the box, but if you don’t, just swap one for the other.

Update Entity Key creation logic

If like me you were manually generating Entity keys in your tests, then you will no longer be able to do so with Persistent 2.1. Replace your old code doing:

Entity (Key $ PersistInt64 1) { foo = "bar" }

with the new:

import Database.Persist.Sql
Entity (toSqlKey 1) { foo = "bar" }

The steps above should take of the most common conflicts that you will encounter when upgrading PostgreSQL-backed Yesod 1.2 to 1.4. Let me know if it’s missing anything.

As always don’t forget to drop by #yesod and #haskell-beginners on Freenode if you have any questions.

Upgrading Yesod 1.2 -> 1.4

Reference Haskell libs for developing great style

Been somewhat busy digging into Haskell recently for our analytics-heavy upcoming web app and couldn’t get a good idea of what quality Haskell code should look like. Sure, there’s LYAH and RWH, and Beginning Haskell, but I like to see live code form authors who are universally considered reputable and well understandable by beginners such as myself. The following libs were recommended for perusal by the fine and generous folks at #haskell-beginners:

There are also a couple of good Stack Overflow posts on the subject if you need more examples:



This should be plenty of reading, back to work.

Reference Haskell libs for developing great style

Early/mid 2014 update – we’re hiring

Whoa, a few months have gone by really fast here. Hi world. Guess I should post an update.

Been hard at work as usual at Front Row, it’s been very interesting to watch our numbers go up at a staggering pace while the # of people supporting the project stays the same. Really makes you appreciate the people making it happen, the tools you’re using and the best practices that keep the whole system from falling apart.

In any case, a few folks and we decided that it was time to give Front Row a bit of a budget to start scaling things out. We’re now looking for a couple of engineers to join us and work closely with yours truly. We’re seeking  web generalists with strong interest in functional programming: we’re a very small team and being able to pick any part of the stack up in a few days is very important. Here’s more info.

Whatever you like, we got it:

  • Want to build super-interactive SPAs and get good at data-visualization? Check.
  • Want to get your hands dirty with ops, configuration management, build automation and continuous delivery? Love Ansible? Check.
  • Want to crunch a ton of data and serve it to the outside world with Clojure and Haskell? Check.
  • Want to build tools and pipelines that enable Front Row content creators to publish their work to hundreds of thousands of students? Check again.
  • Love DBs? We do too! Ours is growing exponentially 😦 If you’d like to contain the beast, we can keep you busy.

That’s it for now!

Early/mid 2014 update – we’re hiring

The hard balance

One of a founder’s toughest logistic challenges is balancing drinking the coolaid of one’s own vision against the iron skepticism that is required for making healthy data-driven decisions.

With the vision, we’re in the land of dreams: Ok, I convinced myself, the team, the people investing in us, the people paying for our services and the people using them that the world is one day going to work according to our bold vision. I claimed that this is how it’s going to be, it’s inevitable, it’s coming and we might as well be the ones executing on it. I claimed that you are all going to behave the way we predict for the foreseeable future.

In the real world on the other hand, a realm of estimates, percentages, decision-making through empirical means, nothing ever goes according to plan. You make a prediction, you test it, most of the time you discover missing a subtle but fatal nuance: one of your assumptions was wrong and you now need to try again with a different set of variables. Rinse and repeat. Maybe you overcome a local maximum, then you run into the next one which turns out to invalidate everything you had done up until that point. Oops, months wasted, time to go all the way back and try again. You just discovered one more way something couldn’t work.

The trick is that you need to convince everybody else of being right, yet at the same time you have to relentlessly try to prove yourself wrong: you most likely missed something and the plan won’t work until all the kinks are ironed out. It’s a very hard line to walk, it’s working every day through cognitive dissonance, getting used to it and not letting it stop you from making progress.

The hard balance