See our books for programmers (Rails, React.js, blogging, remote)

Robert Pankowecki


Why would you even want to listen about DDD?

You might have heard about this thing called DDD which stands for Domain-Driven Design. The name does not reveal much about itself. So maybe you wonder why should you listen about it. What’s so good in it? What problems does it try to solve?

continue reading →

Safer Rails database migrations with Soundcloud's Large Hadron Migrator

When I first started using Rails years ago I fell in love with the concept of database migrations. Perhaps because at the time I was working on commercial projects in C# which lacked this and I could feel the difference. The fact that for many years the concept remained almost the same with some minor improvements speaks for itself. Ruby on Rails continues evolving all the time but migrations remain simple.

However, there is an elephant in the room.

continue reading →

Patterns for dealing with uncertainty

In programming we are often dealing with an uncertainity. We don’t know, we are not sure if something happened or not. Or we are not sure about the result. Especially when it comes to networking/distributed systems but also in other contexts. What I find interesting is that in many cases the techniques used to handle such problems are very similar.

continue reading →

Hourly Billing is Nuts

When it comes to my salary, I am an ordinary guy who earns $ X per hour. I’ve been working this way since I joined Arkency, and I never thought much about it. I’ve been happy that if I need vacations or break, I can just take them (properly communicating it with the clients, of course) without much hassle. When I feel great, and I am inspired to work and work and work, I can just log more hours without thinking much about it as well. Just like monthly salary, hourly salary is a safe way to live. But is it the most rewarding way to live?

Hourly Billing is Nuts challenged my perception that hourly billing is the best way possible. I started to notice the bad parts as well, not only the good ones. I don’t agree completely with some parts of the book, but it got me thinking.

continue reading →

The freelancer in you that wants to be FREE

Do you sometimes as a developer/freelancer/company owner have the feeling that you are being used? Not adequately paid? Treated like a resource?

That considering all the effort, time, investment, the school you went through you should earn more and live a happier life?

continue reading →

To blog or to write code?

Four years ago when I started writing first posts on Arkency blog, I didn’t have many expectations. I knew I wanted to share my knowledge and thoughts. Not much beyond that.

continue reading →

Minimal decoupled subsystems in your rails app

There are multiple ways to implement communication between two separate microservices in your application. Messaging is often the most recommended way of doing this. However, you probably heard that “You must be this tall to use microservices”. In other words, your project must be certain size and your organization must be mature (in terms of DevOps, monitoring, etc.) to split your app into separately running and deployed processes. But that doesn’t mean you can’t benefit from decoupling individual subsystems in your application earlier.

continue reading →

Implementing & Testing SOAP API clients in Ruby

The bigger your application, the more likely you will need to integrate with less common APIs. This time, we are going to discuss testing communication with SOAP based services. It’s no big deal. Still better than gzipped XMLs over SFTP (I will leave that story to another time).

I am always a bit anxious when I hear SOAP API. It sounds so enterprisey and intimidating. But it doesn’t need to be. Also, I usually prematurely worry that Ruby tooling won’t be good enough to handle all those XMLs. Perhaps this is because of some of my memories of terrible SOAP APIs that I needed to integrate with when I was working as a .NET developer. But SOAP is not inherently evil. In fact, it has some good sides as well.

continue reading →

Always present association

Recently my colleague showed my a little trick that I found to be very useful in some situations. It’s nothing fancy or mind-blowing or unusual in terms of using Ruby. It’s just applied in a way that I haven’t seen before. It kind of even seems obvious after seeing it :)

continue reading →

Domain Events Schema Definitions

When we started three years ago publishing Domain Events in our applications, we were newbies in the DDD world. I consider the experiment to be very successful but some lessons that had to be learned the hard way.

continue reading →

Cover all test cases with #permutation

When dealing with system which cooperate with many other subsystems in an asynchronous way, you are presented with a challenge. Due to the nature of such systems, messages may not arrive always in the same order. How do you test that your code will react in the same way in all cases?

Let me present what I used to be doing and how I changed my approach. The example will be based on a saga but it applies to any solution that you want to test for order independence.

continue reading →

How I hunted the most odd ruby bug

Every now and then there comes a bug in programmer’s life that is different than anything else you’ve encountered so far. Last time for me it was 3 days of debugging to find out that MySQL was returning incorrect results. We didn’t have to do much to fix it. We removed an index and created it again from scratch. There, problem gone. But that was a few years ago.

Last week I was hunting an entirely different beast. But before we dive into details, let me tell you a bit about the business story behind it.

continue reading →

Custom type-casting with ActiveRecord, Virtus and dry-types

In Drop this before validation and just use a setter method I showed you how to avoid a common pattern of using before_validation to fix the data. Instead I proposed you just overwrite the setter, call your custom logic there and use super. I also showed you what you can do if you can’t easily call super .

But sometimes to properly transform the incoming data or attributes you just need to improve the type-casting logic. And that’s it. So let’s see how you can add your custom typecasting rules to a project.

And let’s continue with the simple example of stripped string.

continue reading →

2 years after the first event - The Saga Pattern

As you build more advanced solutions, you may find that certain interactions in your system depend on more than one bounded context. Order, Inventory, Payments, Delivery. To deliver one feature often many sub-system are involved. But you want the modules to be isolated and independent. Yet something must coordinate their work and business processes. Welcome the choreographer - the Saga Pattern a.k.a. Process Manager.

continue reading →

Private classes in Ruby

One of the most common way to make some part of your code more understandable and explicit is to extract a class. However, many times this class is not intended for public usage. It’s an implementation detail of a bigger unit. It should not be used be anyone else but the module in which it is defined.

So how do we hide such class so that others are not tempted to use it? So that it is clear that it is an implementation detail?

continue reading →

In-Memory Fake Adapters

There are two common techniques for specifying in a test the behavior of a 3rd party system:

  • stubbing of an adapter/gem methods.
  • stubbing the HTTP requests triggered by those adapters/gems.

I would like to present you a third option — In-Memory Fake Adapters and show an example of one.

continue reading →

Monitoring services and adapters in your Rails app with Honeybadger, NewRelic and #prepend

The bigger your app gets the higher chance that it will need to integrate with multiple of external services, providers and APIs. Sometimes they work, sometimes they don’t. Sometimes it doesn’t matter when they are down or behaving problematically. Sometimes it costs your clients money.

Like when a payment gateway is having problems on Black Friday.

Can you imagine?

But the first step to knowing about the problem and the urgency of a situation is to monitor it. So we will start with that.

continue reading →

Run it in a background job, after a commit, from a service object

There is this problem that when you schedule a background job from inside of a running database transaction, the background job can kick in before the transaction is committed. Then the job can’t find the data that it expects to already be there, in database. How do we solve this issue? Let’s schedule a job after db commit.

continue reading →

Testing race conditions in your Rails app

From time to time, there comes a requirement in your application where you have to guarantee that something can be done at most X number of times. For example, only 15 people can subscribe to a course, only limited number of people can buy this physical or virtual product, only 200 people can go to a concert, etc. How do you test that this limitation actually work? And not only work but that it works under heavy load, when there are multiple customers trying to buy the last item because it is a hot event or the product is offered with a big discount?

continue reading →

Null Object pattern in practice

Wikipedia describes Null Object as an object with defined neutral behavior.

Martin Fowler says Instead of returning null, or some odd value, return a Special Case that has the same interface as what the caller expects.

But null object pattern can also be seen as a way to simplify some parts of your code by reducing if-statements and introducing interface that is identical in both situations, when something is missing and when something is present.

continue reading →

On my radar: RethinkDB + React.js + Rails

Sometimes you hear positive things about a technology and you put it on your radar. To explore it when you have some time. To get a feeling if it is fun at all. To mix and match things together to see what comes out of it.

For me recently it was RethinkDB . Its slogan says The open-source database for the realtime web. Interesting enough to get me curious. RethinkDB pushes JSON to your apps in realtime also sounded good.

I was sick one week ago so I had a moment to give it a try.

continue reading →

How to get anything done? - 4 tips

If you have low self-esteem and constantly worry (like I do), your own thoughts might be the biggest obstacle preventing you from getting great things done. Here are 4 mental tips that I use to overcome my objections.

continue reading →

Adding videos embedded in a page to a sitemap

One of our customer has a solution that allows them to quickly create landing pages that are then used for SEM. Of course such pages are listed in the sitemap of the application domain. The lates addition to that combo was to list the videos embedded on the landing pages in the sitemap. It sounded hard, but turned out to be quite easy.

continue reading →

Ruby Exceptions Equality

Few days ago my colleague was stuck for a moment when testing one service object. The service object was responsible for a batch operation. Basically operating on multiple objects and collecting the status of the action. Either it was successful or failed with an exception. We couldn’t get our equality assertion to work even though at first glance everything looked ok. We had to dig deeper.

continue reading →

It's easy to miss a higher level concept in an app

Just yesterday, I finished reading Understanding the Four Rules of Simple Design written by Corey Haines. I definitely enjoyed reading it. The examples are small, understandable and a good starting point for the small refactorings that follow. It’s a short, inexpensive book, but dense with compressed knowledge, and I can only recommend buying it. You can read it in a few hours, and contemplate it for much longer.

One of the examples inspired me to write this blogpost about higher level concepts. What does that even mean? Especially in terms of programming?

continue reading →

The categories of validations

There are many reasons why rails changed the landscape of web development when it was released. I think one of the aspects was how easy it was to communicate mistakes (errors) to the user. Validations is a very nice convention for CRUD applications. Over time however, many of our active record objects tend to grow in terms of validations. I think they fit at least into a few categories (probably more).

continue reading →

Don't forget about eager_load when extending autoload paths

I am sure you know about config.autoload_paths. A setting which allows you to add aditional directories (besides app/* which works out of box) that can be used for placing your .rb files. The documentation mentions a config.autoload_paths += %W(#{config.root}/extras) example. But the most common way to use it is probably to add lib directory (especially after the transition from rails 2 to rails 3).

Another (maybe not that common) usecase is to have some components (such as notification_center for example) in top-level directory. To make it possible for them to work with your app people are usually using:

config.autoload_paths += %W( #{config.root}/notification_center )

or

config.autoload_paths += %W( #{config.root}/notification_center/lib )

And it is all cool except for one thing they might have forgotten to mention to you. How it all works in production and what you can do to make it work better.

continue reading →

React.js and Dynamic Children - Why the Keys are Important

Recently I’ve been building a pretty dynamic interface based on google analytics data for one of our customers. There was a bug that I couldn’t quite figure out because of my wrong understanding of how react works. In the end it turned out to be a very easy fix and very important lesson on understanding react.js.

It is even pretty accurately described in react documentation however without showing what will go wrong and what kind of bugs you can expect if you don’t adhere to it. In other words, the documentation explains the right way but without going much into details about why.

continue reading →

React.js and Google Charts

So today I was integrating Google Charts into a frontend app created with react.js. As it always is when you want to integrate a 3rd party solution with react components you need a little bit of manual work. But fortunatelly react gives us an easy way to combine those two things together.

continue reading →

Adapters 101

Sometimes people get confused as to what is the roles of adapters, how to use them, how to test them and how to configure them. Misunderstanging often comes from lack of examples so let’s see some of them.

continue reading →

Burnout - do you need to change your job?

I’ve been reading recently a story on Hacker News about a programmer who (depending on who you ask for a diagnose in the thread) was suffering from burnout. Some commenters even suggested depression. There were many advices recommended (unfortunatelly I can’t find a link to the discussion right now) but one certainly spot my attention.

continue reading →

Truncating UTF8 Input For Apple Push Notifications (APNS) in Ruby

When sending push notifications (APNS) to apple devices such iPhone or iPad there is a constraint that makes implementing it a bit challenging:

The maximum size allowed for a notification payload is 256 bytes; Apple Push Notification Service refuses any notification that exceeds this limit

This wouldn’t be a problem itself unless you want to put user input into the notification. This also wouldn’t be that hard unless the input can be international and contain non-ascii character. Which still would not be so hard, but the payload is in JSON and things get a little more complicated sometimes. Who said that formatting push notification is easy?

continue reading →

Using ruby Range with custom classes

I am a huge fan of Ruby classes, their API and overall design. It’s still sometimes that something surprises me a little bit. I raise my eyebrow and need to find answers. What surprised me this time was Range class. But let’s start from the beginning (even though it is a long digression from the main topic).

continue reading →

4 ways to early return from a rails controller

When refactoring rails controllers you can stumble upon one gottcha. It’s hard to easily extract code into methods when it escapes flow from the controller method (usually after redirecting and sometimes after rendering). Here is an example:

1. redirect_to and return (classic)

class Controller
  def show
    unless @order.awaiting_payment? || @order.failed?
      redirect_to edit_order_path(@order) and return
    end

    if invalid_order?
      redirect_to tickets_path(@order) and return
    end

    # even more code over there ...
  end
end

So that was our first classic redirect_to and return way.

Let’s not think for a moment what we are going to do later with this code, whether some of it should landed in models or services. Let’s just tackle the problem of extracting it into a controller method.

continue reading →

Service objects as a way of testing Rails apps (without factory_girl)

There’s been recently an interesting discussion about setting up the initial state of your tests. Some are in favor of using built-in Rails fixtures (because of speed and simplicity). Others are in favor of using factory_girl or similar gems. I can’t provide definite numbers but judging based on the apps that we review, in terms of adoption, factory_girl seems to have won.

I would like to present you a third alternative “Setting up tests with services” (the same ones you use in your production code, not ones crafted specifically for tests) and compare it to factory_girl to show where it might be beneficial to go with such approach.

continue reading →

Effective async communication

What we mean by working asynchronously is not to always work async, to avoid meetings and video calls at all cost. But to rather prefer async way of communicating when it is favorable, when you are sure that sync discussion wouldn’t bring you much more. At first you might think that it is almost never but if you keep pushing yourself a little bit you will soon start to realize that you are getting better at it. In fact now we have much more async discussions than sync discussions.

continue reading →

Mastering Rails Validations: Contexts

Many times Rails programmers ask How can I skip one (or more) validations in Rails. The common usecase for it is that users with higher permissions are granted less strict validation rules. After all, what’s the point of being admin if admin cannot do more than normal user, right? With great power comes great responsibility and all of that yada yada yada. But back to the topic. Let’s start with something simple and refactor it a little bit to show Rails feature that I rerly see in use in the real world.

continue reading →

The biggest obstacle to start with Continuous Deployment - database migrations

Photo remix available thanks to the courtesy of Mark Engelbrecht. CC BY 2.0

There are still companies which disable the website during deploys with database migrations and believe that db migrations prevent them from going fully with CD. They even have time window for triggering such activities (usually early in the morning or late at night).

If you are working in a place like that, and you would deeply want in your heart to adopt Continuous Deployment but you can’t find a way to convince your boss, this is a step by step guide for you. Instead of going from zero to warp nine, you can go towards your goal with small steps that can be part of your current, normal tasks that you are doing for the client.

continue reading →

Zero uptime deploy

Photo remix available thanks to the courtesy of Rob Boudon. CC BY 2.0

Unicorn has a nice feature that bought it a lot of popularity and set standards for other Ruby web servers: The ability to do Zero Downtime Deploy, also known by the name rolling deploy or rolling restart aka hot restart. You start it by issuing USR2 signal. But here is something that most websites won’t tell you. It can fail and you won’t even notice. You will be thinking that everything went ok, living in Wonderland, whereas in reality your deploy achieved uptime of exactly 0 seconds.

So what you need is a small verification procedure that everything worked as expected. This article will demonstrate simple solution for achieving it in case you are using capistrano for deploying the app. However you can use very similar procedure if you deploy your app with other tools.

continue reading →

Don't call controller from background job, please. Do it differently!

Photo remix available thanks to the courtesy of francescomucio. CC BY 2.0

Some time ago while doing Code Review for one of our clients I stumbled on a very unexpected piece of code. Background job calling a controller.

class OrderPdfJob
  def self.perform(order_id, locale)
    controller = PdfController.new
    pdf = controller.generate_pdf_for_order(order_id, locale)
    OrderPdf.create file: pdf, order: order
    # ...
  end
end

class PdfController < ApplicationController
  skip_before_filter :authenticate_user!

  def generate_pdf_for_order(order_id, locale)
    # ...
  end
end

I was a bit speechless. Calling controller out of HTTP request/response loop sounds like an odd thing to do. I had to investigate and refactor.

continue reading →

2 ways to deal with big and complicated features

Photo remix available thanks to the courtesy of EladeManu. CC BY 2.0

From feature vision to stories

One of the challenges of managing software projects is delivering big features. We already told you that we prefer to work with small, prioritized and unassigned stories that anyone can take and finish. But how do any up there? Especially, if what the customer comes to you with, is a big document, describing the features that you must implement.

continue reading →

Pretty, short urls for every route in your Rails app

Photo remix available thanks to the courtesy of Moyan Brenn. CC BY 2.0

One of our recent project had the requirement so that admins are able to generate short top level urls (like /cool) for every page in our system. Basically a url shortening service inside our app. This might be especially usefull in your app if those urls are meant to appear in printed materials (like /productName or /awesomePromotion). Let’s see what choices we have in our Rails routing.

continue reading →

3 ways to do eager loading (preloading) in Rails 3 & 4

You are probably already familiar with the method #includes for eager loading data from database if you are using Rails and ActiveRecord. But do you know why you someties get few small and nice SQL queries and sometimes one giant query with every table and column renamed? And do you know about #preload and #eager_load which can help you achieve the same goal? Are you aware of what changed in Rails 4 in that matter? If not, sit down and listen. This lesson won’t take long and will help you clarify some aspects of eager loading that you might not be yet familiar with.

continue reading →

Developers oriented project management: Leave tasks unassigned

As with software, improving your company is an ongoing process consisting of multiple small steps. If you want your company to be more remote-friendly it is also not all-or-nothing decision. You can gradually start using techniques that will bring you closer to your goal. This series of blogposts is not about why you should go remote, but rather how. Also, we belive that those techniques will help you even if you are not planning to work remotely.

The first part was about having very small stories and how it helps everyone track progress and provides closure. Today we are going to talk about leaving tasks unassigned instead of delegating them to particular developers at the beginning of an iteration.

continue reading →

Developers oriented project management

Working remotely is still a relatively new thing compared to going to an office, which has centuries long tradition. Despite its tremendous growth recently (especially in IT industry), there is not a lot of literature about best practices and working solutions. We still miss patterns for remote collaboration.

Many companies try remote working, but fail at doing it effectively.

They go with the conclusion that it is a broken model. But the truth is, that working remotely is just different, and expecting it to be the same as stationary work, with just people in different places, is the biggest mistake that one can made about it. To fully benefit from it, one must learn how to get most out of it.

You need to learn how to embrace remote work, instead of working around it.

On the other hand, some companies are already there, when it comes to remote working. Or at least they think they are. But is there something more that we can strive for? More ideas that we can try and benefit from? Many of them.

continue reading →

Is it cute or ugly?

Yesterday day I presented a small code snippet to my dear coworkers (who I of course always respect) and (as usually) they were not impressed, even though I liked my solution. So I wanted to know your opinion about this little piece of code. Let’s start with the beginning.

continue reading →

Web is no longer request-reply

In the old times everything was simple. You received a request, did some computation (or not in case of static page) and sent a reply. However what we do now is no longer that easy.

continue reading →

Rails API - my simple approach

I have seen people using very different techniques to build API around Rails applications. I wanted to show what I like to do in my projects. Mostly because it is a very simple solution and it does not make your models concerned with another responsibility.

continue reading →

Blogging for developers

There are many possible blogging platforms out there to be used, yet we decided not to use any of them. It was a controversial decision even inside our own, small team. Before we started blogging there was a heated discussion whether we should use something that can quickly get you running so that when you feel in a mood for a blog post, there are no obstacles preventing you from writing. Or the alternative was to build something custom and have more control. We ended up using existing tools but put a little effort to combine them together into something that we like.

continue reading →

One app, one user, one ruby

There are many ways to install and manage ruby installation in your infrastructure. Some people like rvm, others prefer rbenv, some pack their ruby installation into deb packages. We like nothing.

continue reading →

Sending async data from Rails into the world (II)

In this series of blog posts we discuss possible implementation options for sending data asynchronously from Rails applications. The two common use cases involve delivering exceptions and business metrics to external services.

The second part describes another two solutions: using Thin and classic threads. Read the first part if you have not done it yet.

continue reading →

Sending async data from Rails into the world

Exceptions and business metrics. These are two common use cases involving delivery of data from our Rails application (or any other web application) to external services that are not so crucial and probably we would like to send them asynchronously instead of waiting for the response, blocking the thread. We will try to balance speed and certainty here, which is always a hard thing to achieve.

This is a series of posts which describe what techniques can be used in such situation. The first solution that I would like to describe (or discredit) is ZMQ.

continue reading →

Filepicker and Aviary - Image uploading on steroids

We all have been using the same code for uploading images for years, but didn’t you always feel that there is something wrong with it? For every other task like writing texts, picking a date, selecting from lot of choices we have a good tool that can help in implementing such feature and improve the user experience, but file uploads almost always feel a little broken. There are some Flash tools that might help, but they are still not good enough.

continue reading →