The design of an antifragile Eurozone

Published on

This article is a little bit different than the rest of articles in my blog. Most of my articles are about technology, yet this article may seem related to politics or economics matters. But not really; I am not going to talk about politics.

This article is really about design.

The mission of this article is to lay out a system by which countries, banks and citizens in the Eurozone are not exposed to the risks and failures of each other.

The model

“Model” is a technical word. A model is a simplification of reality, simple enough that it can be understood, but complex enough that it provides enough information to be useful. A model is a tool that we use to understand complex matters in a pragmatic way.

Our model of the Eurozone is going to be composed of four entities: Euro (currency), Banks, Governments and Citizens.

  • The Euro is the currency that the Eurozone uses.
  • Banks are all the banks in the Eurozone.
  • Governments are the organizations ruling each country.
  • Citizens are the regular people living in a country.

Each of this entities has a role:

  • The role of the government is to provide a series of services to the citizens.
  • The role of the citizens is to generate value by creating services and goods.
  • The role of the banks is to lend money and keep money safe
  • The role of the currency is to serve as a mean of exchange for services and goods.

And they have interactions with each other:

  • The money that governments have is provided by the citizens (taxes) and banks (sovereign debt).
  • Citizens expect banks to keep their money safe, that is they can withdraw the money from their bank at any time.
  • Citizens use banks to finance their businesses.
  • Banks lend money to other banks.
  • Governments lend money to other governments.

The risks

“Risk” is another technical word. Risk is defined as the possibility of something happening weighted with its cost.

Since banks lend money to other banks, the failure of one big bank to return a loan can have a domino effect and destroy other banks. This is what happened in the financial crisis of 2008. Banks in U.S.A were exposed to loans that were unlikely to ever be collected. When that risk was realized, the bank had a lot of loses to the point were it was insolvent. Other banks that previously lent money to that first bank were exposed to the possibility of losing that money if that bank were to go bankrupt. This situation spread, domino effect, all over world.

The reaction to this problem was for governments to finance the troubled banks with the money that they collect via taxes. Since most governments operate on a deficit, the money lent to banks was actually obtained via another loan. The disastrous nature of this deal is that it exposes the government to be liable for the failure of private companies. The role of the government in this deal was to act as a proxy between the troubled banks and the organizations that actually contributed the money, and act as collateral – pay the cost of a loan not being repaid.

We don’t pay taxes so that the government can expend it in however way it deems necessary. We pay taxes in order to pay for services the community has agreed to finance, and financing failed banks is not one of those. This strategy has exposed governments to heavy loses, unjust treatment of their shareholders (citizens) and provided only the compensation that rescued banks won’t be failing now – but may, in any case, fail in the future.

Most governments are operating at a loss, their budget has a deficit. Governments are not collecting enough taxes to pay for the cost of the services they provide to their citizens. The difference is being meet using credit from banks. If banks are not willing, or able, to lend money to the government, then the government may go bankrupt.

Businesses depend on banks to finance their operations. If banks are not willing, or able, to lend money to the business, then the business may go bankrupt.

If many businesses go bankrupt, the taxes the government collect are going to be diminished and the government will have a bigger deficit.

Since governments lend money to other governments, if one government, for any reason, is unable to return that money, the lending government may go bankrupt or incur in significant deficit. This is one of the aspects in the Greek crisis of 2015. The governments of Spain, Germany and France were exposed to thousands of millions of Greek sovereign debt and thus their ability to make decisions in a fair way was compromised.

The way in which the Eurozone dealt with the Greek crisis was obviously misguided when we consider the fact that those governments lent money they didn’t had (they operated on a deficit, thereby it was financed by issuing new debt) to pay for services that were not enjoyed by their own tax payers, to a country that was unlikely to return it, that used that money to pay back debt they previously acquired. Ridiculous.

Mitigating risk

So what we have here is a system in which the failure of citizens, governments and banks affect the others. They are very intertwined. Is it possible to build a system in which the failure of one is contained?

I think so. And it will be a simple thing actually. Just a matter of adding these rules to the game:

  • Governments are not allowed to lend money to any other government.
  • Banks are not allowed to lend money to other banks.
  • Only the European central bank can lend money to other banks in the Eurozone.
  • Only the European central bank can lend money to governments in the Eurozone.
  • The European central bank decides if a bank should be lent money.
  • The European central bank must always lend the money governments need.

If governments are not exposed to the debt of other countries, then it doesn’t matter – to them – if they fail. If Greece were to go bankrupt, it would have no impact on the finances of the governments of Germany, France or Spain.

If banks are not exposed to the debt of other banks, then it doesn’t matter – to them – if they fail. If one Spanish bank were to go bankrupt, it would have no impact on the finances of other banks in Spain.

Citizens use regular banks to finance their businesses. Banks are fully capable of absorbing loses of a regular business and if for any reason they are not, then it is only fair that they are allowed to fail – as any other business. Governments are not supposed to lend money to banks under no circumstance.

If only the European central bank were to be exposed to the debt of other banks in the Eurozone, then the failure of a bank will be contained, because the European central bank can always cope with any amount of losses because of the fact it can print money.

If only the European central bank were to be exposed to the debt of governments, then the failure of a government will be contained, because the European central bank can always cope with any amount of losses because of the fact it can print money.

The decision making of lending or not lending to a bank is made exclusively by the European central bank. This is not a political decision, this is an economic decision. A bank is a privately owned business, so the possibility of letting it fail should remain. If the central bank judges letting it fail to be better for the Eurozone than to finance it, it should have the option to.

On the contrary, governments are not privately own, and bankruptcy is a dramatic event for a government, so they cannot be allowed to fail. They should always receive the money. Any country in the Eurozone must be allowed to obtain any amount of credit that their country needs.

If we were to let this rule as it is, it is obvious that it could be abused: countries could just obtain an absurd amount of credit and lower taxes. Such a case would be good for the individual country, but bad for the overall economy of the Eurozone, as it may heavily devaluate the currency. I understand the Eurozone to be an economic alliance of governments that trust each other. If a government were to abuse the system in their own benefit at the expense of others then it is only fair that such a country be expelled from the group. This is a political decision and does not belong to the European Central bank, but to the current leaders of the governments of the Eurozone. It is paramount that government understand that operating on a deficit is to be a temporal strategy to cope with the variability of the economy. It is expected that governments do balance their accounts so as to not have any deficit.

The role of the European Central bank can thought as the entity that is designed to absorb and nullify the effects of dangerous debt. Citizens, businesses, governments, they all have, at some point in their life, the need to acquire a debt. Governments acquire it directly from the EU central bank. Businesses and citizens acquire it from regular banks and, should they fail to pay back, the bank can probably take the hit. If that bank were not able to take the hit, the EU central bank can help by lending them money. This is a system that, by design, makes circular debt impossible. All the negative effects of debt is dealt with, at the very end, by the European central bank. It’s a closed path were debt does not propagate. Banks lending money to governments, and then governments lending money to banks, and again and again until the bubble explodes is an scenario that is impossible within the constrains laid out in this section.


So far we have argued a system in which risk is mitigated. That is, a system in which adverse change can be resisted. But we initially intended to create a system that is not just resistant, but antifragile. An antifragile system, as Nassim Nicholas Taleb defined in The Antifragile, is a system that gains, grows stronger, when change happens. So in that sense:

Does a government that has a deficit and loans money from the central bank make the system stronger?


When a government has a deficit it means that the productivity of said country is not high enough to pay for the services the government is providing. There are only two ways to fix this problem. Either the country increases tax collection, or reduces costs. There is no other way, as a permanent deficit will, sooner or later, bankrupt the country.

Let’s suppose that the government has a fair tax system and no endemic corruption. The effect of the EU central bank lending money to that government is that the government can keep paying for the services it provides to their citizens and also it increases the flow of money in that local economy. So the government will have time to modify their cost structure. Also, when there is an increase in the amount of money in a country it has a positive effect on that economy, thereby is helps in the long term to collect more taxes by increasing the demand services and goods and thus creation of new businesses.

If it were not the case that the government has a proper tax system and no endemic corruption, it would be a country that shouldn’t be in the Eurozone in the first place. It is required that countries willing to join the Eurozone meet certain rules, such as deficit limits. The system is already set, this just need to be enforced – it was not enforced in the case of Greece.

It also has an impact on the currency: it devaluates it. This is not inherently good or bad. It’s good for exports, and it is bad for imports. On principle, the value of a currency is a reflection of the productivity of a country relative to others. In the case of the Eurozone, it is a reflection of the overall productivity of the countries that compose the Eurozone. When businesses in a given country are making a benefit, investors invest in said business. When those investors are foreign, they first need to exchange whatever their currency is for Euros. That increases the demand for Euros, and thus increases its value relative to the other currency. The value of the Euro as a currency is simply a reflection of how well the businesses of a country are doing.

The objective of the Eurozone should not be to maintain the Euro in a particular value, that’s a red herring. The objective of the Eurozone should be to develop an economy that is efficient and productive. The value of the Euro as a currency is simply a reflection of how well we are doing just that. We should not try to maintain the Euro at a particular value by artificial means.

Does a bank that loans money from the central bank make the system stronger?


Under this system, banks can only ask for a loan to the central bank. When a bank needs money, it is because it needs liquidity or because it has loses.

If it has loses, it may be fair to let that bank go bankrupt. It is a private business after all.

Banks have a lot of their money invested. They may have a healthy account, but they may not really have the actual bills available. They lent that money to businesses. But if a bank suddenly need liquidity – actual coins – it should be able to do it because citizens should be able to withdraw their money at any time. Under this model, the European central bank guarantees that citizens will be able to withdraw their money.

Does a business that has a deficit and loans money from a regular bank make the system stronger?


Businesses are the drivers of the productivity of a country. But they fail. A lot.

Under this model, the failure of a business will only impact the lending banks. No domino effect. This is a system that investors can feel a lot more confident in, because risk is mitigated.

To conclude: Building an economic and political system in which the two latest crisis couldn’t had happened is possible. It simply requires that we adopt a system that provides a solid wall between the different actors in this economy, so that the failure of one, does not cause the failure of the other.

Working remotely

Published on

Working in a remote way has many advantages. You have absolute control over when and where you work. The only thing that matters is that you actually get the job done: How you do it and when is your responsibility. This is one of the most positive points of working remotely. It is also one of its weaknesses.

When you work remotely and you get to choose where to work an obvious choice is your own home. That way you don’t need to commute. You are already in the office when you wake up. And that is a problem because, when you work from home, the natural barriers between private life and business disappears. You are no longer ‘Not in the office’. Your coworkers may think that you are available 100% of the time. After all, you have a flexible schedule. The same thing happens from the point of view of your personal life. Because you work from home it may look to other people that you are available to them any time. After all, again, you have a flexible schedule.

When you mix these two points of view you get a clear picture of what it really looks doing remote work from home. There are two groups of people that both demand your time and attention, and since there is no longer a barrier in the form of a formal schedule, you are perceived to be available to them any time.

That is a recipe for being burn out. You need barriers between work and your private life. Otherwise you will be constantly interrupted when you need to be focused on a work task and thus it will take you longer to complete it. Similarly, your attention may be required when you are with your family, thereby creating a conflict between your work and your family. A barrier between the two spheres – work and private life – is important for both effective work and quality family life.

This is one the benefits of choosing to work in a coworking space when you are given the telework option. A coworking space is shared office that is run by a company that is not the one that hires you and that you share with people from other companies. Using coworking spaces have the benefit of creating a barrier between your business life and your private life. You may be working for a company that is based on a different country, but when you are in the coworking space you sure are working, and when you are out of the coworking space you no longer working. There is a barrier, a separation, a boundary that both your company and your family can clearly see and acknowledge.

As a part of Master degree in Business Administration I am doing a research on telework and how coworking spaces can be very effective way of doing it. This study can have a significant impact on how organizations can implement telework in a way that serves both the company and the family needs of the employees.

In order for this study to be successful it needs to be empirical, meaning that I need a big enough pool of people willing to answer my questions. If you have experience doing telework I am very interested in hearing from you. Please join the study and participate. All it will take you is to answer a few questions I will send you next month.

Checkout the website:

And share it :)

The things you may discover when going out for a walk

Published on

I quit my job at Haiku Learning a few weeks ago. It was an awesome job. I worked in very interesting projects that gave me the opportunity to learn; from designing graphical charts with D3JS, to creating API servers and clients, to micro-services and Rails Engines. Thanks to all these projects I have a very solid command of Ruby on Rails and the design principles that guide the creation of maintainable code.

But I lost something when I started working full time. I lost the opportunity to create my own products. My own projects. And that’s exactly where my passion lies.

So quit my job.

I joined a MBA in the university Pablo De Olavide to improve my business skills. I will tell you how that goes :)

Writing an RSpec test for an asynchronous action

Published on

In the previous article you learnt how to write a Rails action that can handle concurrent users, an asynchronous action. Today you are going to learn how to write an RSpec test for it.

This is the controller we want to write a test for:

class ApplicationController < ActionController::Base

  def sample
    EM.defer do
      render json: { response: 'Hello World' }

      request.env['async.callback'].call response

    throw :async


If this were not an asynchronous action, we would simply write a test like this:

require 'spec_helper'

describe ApplicationController, :type => :controller do
  it "hello world" do
    get :sample
    expect(JSON.parse(response.body)['response']).to eq('Hello World')

But this won’t work because throw :async will kill the action right away. throw :async will make the interpreter go to this line of code defined in the Thin gem. The problem is that Thin is not loaded at all when running a controller test.

In order to properly test an asynchronous action you need to run the test using a real Thin server. You can use Capybara to do that.


gem 'thin'
gem 'capybara'
gem 'selenium-webdriver'

In spec/rails_helper.rb:

require 'capybara/rails'

Capybara.default_driver = :selenium

Capybara.server do |app, port|
  require 'rack/handler/thin', :Port => port)

Write the test:

describe ApplicationController, :type => :feature do
  it "my test" do
    visit some_path
    expect(page).to have_content('Hello World')

And that’s it. Happy testing.

How to handle concurrent requests in rails

Published on

Let’s say we have this action:

class ApplicationController < ActionController::Base

  def normal
    sleep 5 # Some code that takes a long time. For example: a web request.
    render plain: 'Hello'


This code is a scalability problem, because each request efectively blocks other requests from being handled. If your service receives more than one request per 5 seconds, your service will start failing to respond. But it doesn’t need to be like that. There is a way to tell Rails that it is okay to handle some other request while some other work is being done and then go back to that original request when all it’s ready.

It’s called concurrent mode.

In this example we will use Thin plus rails’s concurrent mode to handle request concurrently.

The first step is to add the Thin server to the Gemfile. A simple gem 'thin' in the Gemfile will do.

The second step is to activate the concurrent mode in the rails environment. For example, in development:

# config/environments/development.rb
Rails.application.configure do

  ...some other settings

  config.allow_concurrency = true

Then set up the action that you want to handle asyncronously in this way:

class ApplicationController < ActionController::Base
  def async
    EM.defer do
      sleep 5 # Some work that take a long time.
      request.env['async.callback'].call response

    throw :async

Start the server like this: bundle exec thin --threaded -p 5500 --threadpool-size 50 start

That means that Thin will be started in threaded mode, and it will use up to 50 threads. The threaded option is important as Thin defaults to non threaded mode.

When the request is being handled, the EM.defer block will be executed in a separate thread. At the same time the throw :async will be executed, which basically tells the Thin server that this request will be handled asyncronously and that it should inmediately start working on a different request. request.env['async.callback'].call response will communicate the response to the Thin server and send it back to the client.

Let me remark that, until request.env['async.callback'].call response is executed, no response is sent back to the client.

There is one important gotcha with throw :async: No rack middleware will be executed for the response. Thereby if you try to set up a cookie it will fail. But here is a way to fix that:

class ApplicationController < ActionController::Base
  def async_with_cookies
    EM.defer do
      sleep 5
      cookies[:message] = 'hello'
      request.env['async.callback'].call response

    throw :async

cookies.write(headers) will take care of setting the headers that needs to be set in order to make the changes in the cookies. It’s basically the code that gets executed when the Cookie middleware is executed.

And that’s it, so simple.

One way to test that you action can really handle concurrent requests to to query the url with multiple requests at the same time. You can do it with Apache HTTP server benchmarking tool, packaged with Mac OS.

time ab -c10 -n10
# That will send 10 requests, 10 request at a time (so all go in at the same)

➜  Concurrent  time ab -c10 -n10
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd,
Licensed to The Apache Software Foundation,

Benchmarking (be patient).....done

Server Software:        thin
Server Hostname:
Server Port:            5500

Document Path:          /async_with_cookies
Document Length:        2844 bytes

Concurrency Level:      10
Time taken for tests:   5.178 seconds
Complete requests:      10
Failed requests:        7
   (Connect: 0, Receive: 0, Length: 7, Exceptions: 0)
Write errors:           0
Non-2xx responses:      5
Total transferred:      34886 bytes
HTML transferred:       32330 bytes
Requests per second:    1.93 [#/sec] (mean)
Time per request:       5178.076 [ms] (mean)
Time per request:       517.808 [ms] (mean, across all concurrent requests)
Transfer rate:          6.58 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:   196 2687 2614.2   5158    5178
Waiting:      196 2687 2614.2   5158    5177
Total:        196 2687 2614.2   5159    5178

Percentage of the requests served within a certain time (ms)
  50%   5159
  66%   5159
  75%   5164
  80%   5176
  90%   5178
  95%   5178
  98%   5178
  99%   5178
 100%   5178 (longest request)
ab -c10 -n10  0,01s user 0,02s system 0% cpu 5,207 total

So you can see that it took 5 seconds total to handle the 10 requests (each one taking 5 seconds) thereby proving that we can handle concurrents requests. This is a very useful model for handling web requests where one portion of the request may take a few seconds. For example at Haiku we use this technique when handling Google sign in. The portion of the code where we need to wait is simply executed within a Event Machine defered block.

Note: If you use Pow for your app, use the ip address as in the example, because Pow will only handle one request at a time.

You can see a full example here:

Older ›