Micro Gem : A Look at the Future by Looking at the Past

What is a Micro Gem ?

A Micro Gem is a gem that is self-contained and focused on only one feature. The aim of Micro Gem is to make the unit of reuse as small as possible to give it the best chance for survival over time in different contexts.

What is Not a Micro Gem ?

A gem that cuts through different layers is not a Micro Gem. The focus of a Micro Gem is on only one layer.


The Micro Gem is motivated by the desire to separate things that change at different rates. It was painful to see one of my Rails app evolve from 2.2 to 4.2. For instance, Twitter Bootstrap changes at a different rate than Stripe API.

We must contain the dependencies and manage the changes that differ for different reasons independently. This prevents the ripple effects of the changes made to an unrelated layer. It is easier to manage the dependencies in a project using Micro Gems.


A Micro Gem aims for very minimal dependencies on other gems. If we can implement the feature without using any other gem, then we just make it pure Ruby with no external dependencies. There must be only one reason to change a Micro Gem. It must be very simple.

You either use everything provided by the gem or you don't use it at all. It's like a Bento Box. There is no waste. It provides a cohesive service.

Aim Small Miss Small

We aim for 200 lines of code and 2 classes. If we exceed that, we reflect on the code and find a way to reduce it's size without impacting the useful functionality provided by the Micro Gem. The constraint on the code mass forces us to find creative solutions to the problem. We want simplicity not something that is simplistic.


The Micro Gem idea is inspired by the concepts found in Unix, Docker and Micro Services architecture.

  • Unix command line utilities that can be combined in different ways using pipes to solve different problems.
  • Micro Services architecture puts each element of functionality into a separate service.
  • Docker allows you to package an application with all of its dependencies into a standardized unit for software development.

What if we could build a gem that is self-contained and is focused on providing only one feature?

Characteristics of a Micro Gem

  • It is less than 200 lines with one or two classes.
  • You can develop it in a few days.
  • You can express what it does with one phrase.
  • You can easily upgrade in a few hours.
  • Tests run fast because it has only one feature.Yay!

Examples of Micro Gems

  1. Merlot : PDF Stamping
  2. Cognac : Amazon S3 Upload
  3. Colt : Recurring billing using Stripe API

They are all lightweight with useful functionality.


  • Work can be assigned to one developer with minimal communication with other developers on the team.
  • There is no cognitive overload.
  • There is no WTF moments when you look at your own codebase later.
  • You can fit the entire code base in your head. Easy to mull over the codebase and improve the design incrementally over time.
  • It is not intimidating to work on it during your spare time. Because there is very minimal context that needs to be set before you can start doing something. You will not be wasting time to figure out:
    • What should I do next?
    • Where do I start?
  • Satisfaction in completing the development and releasing it quickly. I can say it is 'DONE' which feels good instead of always being in a 'IN-PROGRESS' state which drains your energy.
  • You don't have to be a meta-programming Ninja to develop a Micro Gem. If you found useful snippet of code on stackoverflow, pastie or gist on github, you can easily turn that into a Micro Gem.
  • This encourages even newbies to Ruby to contribute to open source.
  • The mapping of feature to the dependencies required to implement that feature becomes very clear. Take a look at the gemspec file or Gemfile.lock.
  • Does the assumptions not fit your needs? Just fork the repo and customize it to suit your needs.
  • You can encapsulate knowledge in how to articles into Micro Gem.

Right Level of Granularity

All of my Micro Gems are extracted from real projects. So the functionality offered is neither too small or trivial to be used in a real project nor too big to become a maintenance nightmare. It is also easier to see what the simplified API will look like from a client's perspective before the gem is developed.


The UNIX has survived for almost 5 decades and will survive for another 5 decades. What if we could build Micro Gems that could evolve and still provide useful unit of functionality for decades to come? The 'What' is found in the tests, the 'How' is found in the production code and the 'Why' is not found in any form of code. The 'Why' is the design decisions that developers make and it evolves over time. Some of the 'why's can be found in the form of comments, blog posts and as discussion threads between the developers on forums. How can we minimize the time spent on 'Why?'. Can developers become more productive by developing Micro Gems that follow the UNIX philosophy? Only time can answer those questions. Let's see how the future unfolds.

Related Articles

Ace the Technical Interview

  • Easily find the gaps in your knowledge
  • Get customized lessons based on where you are
  • Take consistent action everyday
  • Builtin accountability to keep you on track
  • You will solve bigger problems over time
  • Get the job of your dreams

Take the 30 Day Coding Skills Challenge

Gain confidence to attend the interview

No spam ever. Unsubscribe anytime.