Why shouldn't you use health checks?

This is a reprint of my post on FANDOM's engineering blog.
At FANDOM we believe our applications should be resilient, that is they should be able to recover from failures and while the failure occurs still be useful for the users. Health checks are one of the ways to make applications self-healing.

The idea is that the health checks detect when an instance of the application reaches an invalid state. A supervisor monitors those health checks and attempts to fix any issues. Depending on your platform the action might be different.

Many frameworks (like Dropwizard and Spring) and platforms (like Kubernetes and Marathon) encourage you to implement health checks for your web applications.

When a health check fails, AWS will stop sending requests to that instance. That’s pretty straightforward — we suspect the application is not healthy, so it might not respond correctly. Decreasing load on it might also help it recover. In Kubernetes, there’s a readiness probe behaves like AWS. There’…

Geecon 2015

So last month I've attended Geecon and I really loved it. Geecon is a conference focused on Java and JVM technologies, hosted annually in Cracow (usually).
This year’s it was all about microservices, so it’s no surprise that I enjoyed Fred George’s “Challenges in implementing microservices” the most.

In his talk Fred George shared his experiences with replacing monolith applications with microservices. He explained how microservices facilitate a Service Oriented Architecture and “going faster” as shorter reaction time for the whole company.

What was most interesting to me was the comparison of asynchronous and synchronous approaches to microservices. He mentioned his friend Chad Fowler suggests synchronous communication on default mainly because it’s easier for most of the modern programmers. In contrast Fred George believes that asynchronous messaging gives so too much of an opportunity for robustness and graceful degradation to ignore in exchange for simpler implementation.


Creation method in Mongoose.js, alternative to custom constructor or hooks

Creation method is a neat way of creating objects in the same way by using the object's well-named static method instead of constructor. While similar, creation method should not to be confused with factory method pattern, which involves the concrete implementation of created objects). If you'd like to know more about creation method's benefits and application I highly recommend Joshua Kerievsky's Refactoring to Patterns.

Here's how this alternative to custom constructor or hooks can work in Mongoose.

Let's use an Article model in Mean.js app generated by Yeoman as an example:
Let's say we'd like article to have an url field, which we'd like to generate from the title. We'd like to avoid copying the url generation code everytime we'd like to create an article. One way to do this is to create a creation method which does that.
Since all static methods have to be defined before the model class is created creating a creation method the follow…

Mavenized Java server application and Angular.js frontend application using yeoman

Setting up Angular.js using YeomanIn Gruntfile.js change application config, so the application is compiled into java resourcesFinally add build plugin to pom.xml so the js appliacation and all of its resources are built into your Java resources. Notice that for workingDirectory I'm using my directory 'ui'.The build should pass and you can deploy your appliacation to a server container of your choosing.I'm using Spring (along with Spring Boot). A simple controller like this:Should yield a result like this: I've based this article on Gunnar Hillert's Botanic-ng and my own experimentation.

Calculating values for bar charts in LaTeX

The bchart packageIf you want to add some bar charts to your latex document you might want to use bchart. This pdf by Tobias Kuhn shows some examples of how to use the package. Description taken from that pdf: bchart is a LATEX package for drawing simple bar charts with horizontal bars on a numerical x-axis. It is based on the TikZ drawing package. The focus of this package is on simplicity and aesthetics. Using the package one can display labels, specify the axis range, bar colors or unit of the values.Calculating valuesUnfortunately the package has a drawback. If you use math expressions they will be calculated for the bars but wont their values won't be displayed. In addition you cannot use \pgfmathparse{} to calculate the value for the chart because it will cause errors in displaying the bars.Which renders: I believe it is due to internal usage of pgfmath of the package.There is a simple solution though, using \\pgfmathsetmacro{}{}:Which renders:

Setup SQL Server 2012 and Adventure Works cube with Visual Studio 2010

This tutorial will show you how to deploy a cube onto SQL Server 2012 using VS2010 and might help you avoid some of the problems I've encountered. It is complementary with Multidimensional Modeling (Adventure Works Tutorial) and uses its Adventure Works db and cube project.While this states that it is not possible to deploy a cube using Visual Studio it is no longer the case with SQL Server 2012.PrequisitesVisual Studio 2010 disc or imageInstalled Visual Studio 2010SQL Server 2012 disc or imageService Pack 1 for VS2010 due to thisInstalling SQL Server 2012 or adding required featuresNote: Running VS2010 during the installation might cause errors so close it.Run SQL Server Setup by selecting New SQL Server stand-alone installation or add features to an existing installation from Installation tab of the SQL Server Installation Center. Move through the process up to Installation Type. If you already have an installed SQL Server you would like to use, pick Add features options and sel…

MongoDB and distinct values in arrays

This post is a mini-tutorial on how to deal with array fields in MongoDB, specifically arrays of items that may or may not be duplicated.Let's create a collection of unicorns, smilarly to The Little MongoDB Book examples:
Find should now return something like this, the _ids will vary:Adding a value into an arrayWe've found out that our unicorn Scott also loves playing games, so lets push a new value into our document's loves array:Using push, we could insert into our the same value multiple times.Pushing a value if its uniqueWe have found out that all our unicorns love movies and want to update the whole collection. Unfortunately Scott already has got movies in his loves field. As shown here, we can use addToSet, which won't add a duplicated value to an array:The third parameter of update is upsert(false by default). The fourth is multi which makes the query update every document that matches the criteria (false by default meaning that it only updates the first one). Yo…