Implementing a domain model using functional programming in Scala.

It’s been a long time since I was thinking about writing such an article. The final enlightenment occurred when after a few projects with non-trivial domains I read Domain Modeling Made Functional by Scott Wlaschin. This is where I made several observations I’d like to share.

Scala is a perfect match for modeling complex domains. Its advanced type system allows expressing business concepts and rules more precisely and directly. What we gain with it is the code that is more type-safe, descriptive, and easier to understand. …


A story about safe and compositional resource management in vanilla Scala and cats-effect.

We’re all using resources on a daily basis. You turn on the water tap, wash your hands for at least 20–30 seconds, and turn it off. You switch the light on if it’s dark, and off when you no longer need it.

Resources have a lifecycle. You open them, use them, and close them afterward. Not only light and water taps fall in that category, but also all kinds of database connections, HTTP servers, clients, files, or streams.

What’s interesting about resources is that they often depend on each other, so we care about the ordering of their acquisition and release. We want to see how we wash our hands, so we switch the light on before turning the water tap. If a database is used for processing HTTP requests, we want to connect to it first and after that, we start the HTTP server. However, during the application shutdown, we want to stop the HTTP server, and then close the database connection. …


A short read about being careful with error handling in stream design.

Akka Streams is a reasonable choice when it comes to event processing. A wide variety of connectors and integrations makes it easy to assemble a working pipeline and get up to speed quickly.

On the other hand, we have a long list of predefined operators, GraphDSL, support for error handling, a possibility of rolling out custom stages and more. It means, that having a rough idea of what do we want to achieve, there is always a number of ways to approach the stream design. It’s quite easy to assemble a working graph. But to make the code scalable, maintainable and easily extendable, it usually needs experimentation and playing around with different approaches. …


Using ngrep and nginx to debug HTTPS like a pro!

Imagine you’re investigating a strange issue with a web service that talks to other services using HTTP over TLS. You want to inspect the HTTP calls it makes and what responses it gets back.

…and it’s 2018, so you’re running the service in a shiny container!

The first obvious approach would be to increase logging. This is very cool if the service you’re debugging allows to do it. But what if it doesn’t? What if you are not allowed to modify the source code and add it yourself? …


Using Akka Streams to stream data from Amazon S3 to MongoDB.

This is part two of the Crafting production-ready Backup as a Service solution using Akka Streams series. I highly encourage you to read the first part first if you didn’t, since it gives an overall context.

In the first part, we saw how to perform a data backup from MongoDB to S3 by composing a stream with encryption and compression using Akka Streams and Alpakka.

In this part, we’ll focus on doing the restore. We’ll again use Akka Streams and Alpakka to stream the data stored in S3 to MongoDB. We’ll also face new interesting challenges, as doing the opposite is not always straightforward ;). …


Using Akka Streams to backup MongoDB to Amazon S3.

Edit: both parts of this article are up to date as of 16 Jan 2019.

Imagine you’re developing a database as a service solution like Compose or mLab. You’re hosting a horde of database instances/containers which are used by your customers. One of the key features of your solution is performing backups since no one is willing to lose data. You are already doing backups in form of e.g. volume snapshots, just in case of a disaster in your infrastructure (and you obviously test your automated recovery procedure frequently to prove it’s up to date ;)).

What if you wanted to let your customers do automatic backups of their data (or some selected part of it), so they could restore it on demand? …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store