Showing posts with label devops. Show all posts

5 Reasons to use the Feature pattern in your product

A design pattern is a formal way of documenting a solution to a design problem.

The "Feature" design pattern is a simple yet powerful mechanism that enables you to rollout features based on configuration settings. It provides the ability to turn these high-level features "on" or "off" by changing the configuration parameter values. The basic idea: use a simple mechanism to control the features that are presented to the end user.

5 Reasons to use the "Feature" pattern in your product

1. Reduces the need to branch: The longer your branch remains unmerged, the greater chance that it will never make it. By being able to not turn the feature "on" until ready in production, but continue to work in the main or trunk branch is valuable.

2. Partial rollbacks (isolated): A single new feature will not hold up a production deployment, it can be turned "off" until ready. It keeps progress moving and a feature rollout does not have to necessarily coincide with a code rollout.

3. Different features for different folks: Will make it easier to turn a feature "on" for testing in a particular environment, but "off" for your production environment. It can also help with partial user and A/B testing.

4. Helps reduce risk: With the ability to turn features "off" until ready, it can allow you to increase development velocity without necessarily increasing risk.

5. Used by #winners: Facebook, Amazon, and many others. Today, Facebook has many new features that are not yet turned on yet but deployed to their production environment. Although not an intended reason, Facebook has even turned on features in production to react to new features from Google+. Features ready to be turned "on."

My hope: the "Feature" pattern will help you for the same reasons.

For more details about the Feature pattern, see the somewhat terse pattern description below along with the source code. There is not much to this simple yet powerful pattern.


Pattern Name: Feature

Intent
Provide a simple yet powerful way to turn features "on" and "off" via configuration. This enables certain environments to have certain features turned "on."

Also Known As
Feature toggle.

Motivation (Forces)
Demand for high development velocity and the need to mitigate risk.

Applicability
Web apps, freemium business models, mobile apps, services, etc.

Structure
The pattern structure is simple and consists of the Feature class. 

Participants
Feature: Represents a Feature that can be turned on or off based on an app setting. You can take an action if it is on, off, or both.

Collaboration
Here is an example code fragment that interacts with Feature:

           Feature.BasedOn("Product.Feature.IsOn")
                .IfOn(() =>
                {
                    // do the feature
                })
                .IfOff(() =>
                {
                    // do the alternative or not
                });

If the the configuration parameter "Product.Feature.IsOn" is set to "true," then the IfOn action will be invoked; otherwise, the IfOff action will be invoked.

Consequences
Be sure to get granularity right.  Be wary of adding features at too fine of detail. Complex feature interaction can also complicate testing. Although a more general discussion, make sure that each feature is justified. However, even in a design world driven by YAGNI and KISS principles, you still need some flexibility—just make sure that it is justified.

Implementation
Here is a simple implementation of the Feature pattern in C# below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;

namespace Product.Support
{
    /// <summary>
    /// Represents a Feature that can be turned on or off
    /// based on an app setting. You can take an action if it is 
    /// on, off, or both.
    /// </summary>
    public class Feature
    {
        /// <summary>
        /// Based on this app setting. 
        /// </summary>
        public string AppSettingKey { get; set; }

        /// <summary>
        /// Create a feature based on the given setting.
        /// </summary>
        /// <param name="appSettingKey">The app setting that determines whether the feature is turned on or off.</param>
        /// <returns>Newly created feature.</returns>
        public static Feature BasedOn(string appSettingKey)
        {
            if (string.IsNullOrEmpty(appSettingKey)) throw new Exception("setting key cannot be null or empty.");
            Feature feature = new Feature();
            feature.AppSettingKey = appSettingKey;
            return feature;
        }

        /// <summary>
        /// Whether the feature is turned on; that is, if the app setting
        /// has a value of true; otherwise, false.
        /// </summary>
        /// <returns>Whether the feature is on; that is, if the app setting
        /// has a value of true.</returns>
        public bool IsOn()
        {
            if (AppSettingKey == null) return false;
            string value = ConfigurationManager.AppSettings[AppSettingKey];
            return (value != null && value.ToLower() == "true");
        }

        /// <summary>
        /// Performs the given action if the feature is turned on.
        /// </summary>
        /// <param name="action">The action to take.</param>
        /// <returns>The feature</returns>
        public Feature IfOn(Action action)
        {
            if (IsOn())
                action.Invoke();
            return this;
        }

        /// <summary>
        /// Performs the given action if the feature is turned off.
        /// </summary>
        /// <param name="action">The action to take.</param>
        /// <returns>The feature</returns>
        public Feature IfOff(Action action)
        {
            if (!IsOn())
                action.Invoke();
            return this;
        }
    }
}

Sample Code
As sample code, here are some unit tests that interact with the Feature class:
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Product.Support
{
    [TestClass]
    public class FeatureTests
    {
        [TestMethod]
        public void Feature_IsOff_Success()
        {
            // arrange
            bool isPass = false;

            // act
            Feature.BasedOn("Product.Feature.IsNotOn")
                .IfOn(() =>
                {
                    isPass = false;
                })
                .IfOff(() =>
                {
                    isPass = true;
                });

            // assert
            Assert.IsTrue(isPass);
        }

        [TestMethod]
        public void Feature_IsOn_Success()
        {
            // arrange
            bool isPass = false;

            // act
            Feature.BasedOn("Product.Feature.IsOn")
                .IfOn(() =>
                {
                    isPass = true;
                })
                .IfOff(() =>
                {
                    isPass = false;
                });

            // assert
            Assert.IsTrue(isPass);
        }
    }
}

Known Uses
Facebook, Amazon, and others.

Related Patterns
For a couple more previously unpublished patterns (Instrumentation and Service Protector), check out this article that I wrote for the Microsoft Developer Network last year, WCF Decision Framework:
http://gregcowin.blogspot.com/2011/08/why-use-decision-framework.html


Enjoy the pursuit of great design.

Who makes the best keyboard? 7 reasons.

For the past four years, I have been using, in my view, the best keyboard ever made—especially for Windows development. The maker might surprise you. It is the Apple keyboard (ultra slim). It sells for $49 and that is luckily within reach for most of us. If you have a PC with a USB port, it just works. If you have not used a Mac recently, it has a control, alt (option), and command key. The command key becomes the Windows key. There are a lot of people that run Windows on Apple hardware so it needs to work.

I have tried what seems like a reach of different keyboard types including split, natural, heavy tactile and gaming keyboards. In 1997, I even tried the Dvorak keyboard layout instead of QWERTY for three months in hopes of typing a little faster.

Tools become an extension of our bodies. Typing becomes an extension of us just as using a mouse, or Natural User Interface (NUI) of tablets, phones, and gaming consoles. The idea that Your Computer is a Part of You is the result in a recent study done by cognitive scientists at Franklin & Marshall College. The results seem to indicate that people do fuse with their tools—cognitively at least.

Currently, Apple makes the best keyboard, in my view.

7 Reasons


1. Easy to type
Smooth hurdling (awkward stroke requiring a single finger to jump directly from one row to another row). The keyboard gets out of the way to a large degree.

2. Low profile
The keyboard is so slim that there is no hand rest needed; it feels good; just slide your hands forward naturally on it.

3. Short key travel
Helps me type faster and smoother. Has a nice short crisp tactile feedback.

4. Easy to clean
Let's face it, keyboards make excellent homes for nasty bacteria.
When keys are pressed, they are at the level as the aluminum making it easy to clean since you can clean the base and keys at the same time with a swipe of a paper towel.

5. Beautiful
Heavy for its size; made of aluminum with flat rounded rectangular white keys.







6. Simple
Not a ton of extra keys, but all the ones you really need.

7. Easy key combos (such as Shift+Ctrl+B)
Just press between the two keys until you feel aluminum; this is one reason that I like it for development; it requires a lot of odd key combinations and symbols.

I first got an Apple keyboard for home. It was fun to type again. Typing became simple, not over-manipulated. Now, I try to bring one with me anytime that I will be riding a workstation for a while. It is slim even in the box.

In my view, the Apple slim keyboard is great design. It is simple, lasting, and like other great interfaces, it gets out of the way. Granted, you might not like it as much as I do, but definitely a keyboard to consider.

I hope that the command center will even have a few.

Enjoy.


Additional references
Print Screen in Windows - F14
Key mappings and comparison

Why use a decision framework?

In my view, a decision framework represents a simple, yet potentially powerful, sequence of decisions to make and actions to take. Teams, projects, and clients must navigate effectively when tackling new business opportunities, projects, and technologies. A decision framework structures information in a way that makes it easier for people to make decisions and take actions.


A decision framework can help you...
  • Avoid traps and pitfalls such as analysis paralysis
  • Converge on the right decision
  • Take action
  • Do the right thing (most important of all)
For an example of a decision framework, check out this article that I recently wrote for the Microsoft Developer Network (MSDN). The article is a decision framework for WCF (Windows Communication Foundation) development. WCF is a unified communication framework in .NET for building connected, service-oriented applications:


The article also contains a couple of previously unpublished patterns: Instrumentation and ServiceProtector. I hope that the framework will help you develop the SOA that is right for your organization and that you also find it engaging.

Please let me know what you think of the decision framework method. I think that it has potential to be used in a lot of areas. I have already started simple decision frameworks for Azure and TFS.

In my view, the decision making process is the key to great design, but perhaps not in the way you that you might think—more to follow.

Enjoy!

Top 3 reasons why cloud computing is unstoppable

In my view, here are the top 3 reasons why cloud computing is unstoppable:

1. Business Continuity
2. Operational Agility
3. Cost


Business Continuity
Business continuity is about ensuring that critical business functions can continue smoothly not only in the event of disaster, but other events such as acquisitions, moves, bankruptcies, getting a large customer, loss of key personnel, loss of a large customer, etc. All can cause havoc on business continuity. These events are critically important to business stakeholders—the people ultimately in charge of how IT money is spent.

Today, the pace of business change is significant: new product offerings, uptakes, downturns, acquisitions, geographic expansion, moves, exponential growth, spikes, campaigns, etc.

Imagine a scenario: you acquire a company with a mess of servers, network, cabling, and software installs. It takes time to move these systems and components into a parent company—many times failing completely. The desire of the parent company is to incorporate the acquisitions and hit the gas pedal, but it is often slow and affects business continuity.

Some companies are financed in hopes of being acquired as an exit strategy, but the back end simply is not structured for it. You could be a lot more desirable to be acquired if you have standard deployments in the cloud.

Imagine that you are a small to medium-sized business and your biggest customer, a Fortune 50 company, wants to use your solution for their entire company. In this kind of deal, a software escrow agreement will not be enough; they will want your solution to be in the cloud. So that in the event that your company goes under, they can just take ownership. They acquire this virtual property as opposed to trying to figure out a mess of software and hardware that is hard-coded to a particular location with odd configuration and deployment.

The cloud, particularly Platform as a Service (PaaS), provides key mechanisms to help with business continuity: elasticity, redundancy, standard deployments, etc. You are protected against disaster, able to scale up or down within minutes, not weeks, months, or years. The standardized deployments are easily understood and can be smoothly transitioned to a new team—not a mess of custom scripts, installs, and manual error-prone magic.

For example, Windows Azure provides triple redundancy of the Azure Storage and SQL Azure. It keeps three synchronized copies. This is often never done even for critical systems because of the complexity and expense of having redundant data centers. Azure maintains three copies of your data and can failover to another geographic location. It is built into their Cloud OS—really the fabric of the cloud.

In my view, the killer benefit of cloud computing is business continuity.

Operational Agility
Especially with Platform as a Service (PaaS) such as with Microsoft Azure, operation agility is achieved by providing an architecture that can easily scale horizontally. You can dynamically allocate these containers of services up or down. You can be much more efficient with just the capacity that you need with a pay-for-use model.

If you are deploying on virtual machines or physical machines, you must plan for peak capacity. Planning for peak capacity can be manageable if your load is consistent, but is usually a challenge. Ideally, you plan for an efficient amount of over capacity. This can be very difficult—impossible to estimate. Often times driven by fear, systems are dramatically over deployed—not efficiently over deployed.

This kind of operational agility will change business models. My understanding is that Pixar has recently deployed RenderMan into the cloud and is able to burst it when needed to make a movie and make it available as a service to smaller studios.

The ability to burst out to 1000's of computing containers then back to zero will create new business opportunities—even for the little guys.

Cost
It is easy to spend 1/2 million bucks on a few servers, SANs, load balancers, network equipment, racks. Make it redundant and then double that along with your provider rates. It is a big capital expenditure and it will still have to wait weeks until it is ready to be used and much longer for complex issues to be resolved.

With the cloud, it is a pay-for-use model without the huge upfront capital expenditures. You can leverage economies of scale and best practices. Microsoft has invested 8 billion in their cloud initiative. Based on a platform briefing that I attended at Microsoft, they are buying 1 out of 4 servers in the US and 1 out of 3 servers world-wide. How can you compete with this economy of scale.

The starting retail price for Windows Azure currently costs 5 cents per computing hour. Everyone that I have dealt with has a 70%+ savings in total cost of ownership. It is significant.

Closing
Manufacturing companies used to maintain their own power plants in the early days of the industrial revolution, now, everyone uses and trusts power as a utility. In my view, Windows Azure is far closer to utility computing than any other cloud provider. You do not have to maintain the stack. It provides elasticity of demand. You have a utility of computing and storage containers.

The same will be true for industrial computing, it will take a while, but it will happen. Don't wait too long, because someday you might have a 30% cut in your IT budget and it will hurt because you will be upside down.

I have been working with Microsoft Azure. Microsoft Azure has all three. In my view, Microsoft is the clear leader in cloud computing or more broadly, IT as a Service that includes SaaS (Software as a Service), PaaS (Platform as a Service), and IaaS (Infrastructure as a Service). Microsoft is "all-in" with the cloud.

Does your environment provide you with all three?

Let me know what you think about the key benefits of cloud computing.

What is the killer benefit of cloud computing?

The killer benefit is business continuity. With cloud computing, businesses can improve continuity when faced with real-world events: acquisitions, bankruptcy of a vendor, escrow deals, loss of personnel, moves, growth, and others. This improved continuity helps increase velocity and momentum necessary for growth.

The reason: business continuity is a big deal to investors, stakeholders, and customers. They are the very people that drive these kinds of decisions. It will likely not be the CIO or Director of IT, but a customer that pushes you into the cloud.

Imagine that you are a small to medium-sized business and your biggest customer, a Fortune 50 company, wants to use your solution for their entire company. In this kind of deal, a software escrow agreement will not be enough; they will want your solution to be in the cloud. So that in the event that your company goes under, they can just take ownership. They acquire this virtual property as opposed to trying to figure out a mess of software and hardware that is hard-coded to a particular location with odd configuration and deployment.

Imagine another scenario: a company loses a vast amount of data because of hardware failure and did not notice that their backups had been failing for the past 6 months. Or a RAID 10 system is lost due to administrative error. By the way, evidently most arrays are lost due to human error. There are a ton of other scenarios like these that can hamper business continuity. The result of any one of them can be detrimental.

Cloud computing will also reduce capital and operating expenditures; also, likely to appeal to stakeholders, but business continuity is the killer benefit that will push companies into the cloud.

In my view, cloud computing is great design. What do you think?

Can command and control ever lead to great design?

No. At best, it can lead to good design but never great. Here is a quote that helps make the point from a wonderful book about how man made things are becoming more lifelike and life is becoming more engineered called Out of Control: 
"The USSR didn't collapse because its economy was strangled by a central command model. Rather because any central-controlled complexity is unstable and inflexible. Institutions, corporations, factories, organisms, economies, and robots will all fail to thrive if designed around central command."

From my view, there is nothing elegant or great designed by command and control. It cannot be great because it is not
sustainable. Can you provide a counter example? I am curious. 

The quote is from page 42. After locating the reference, I found that
Out of Control is 15 years old, but it is still a fantastic book. Leads me to another question: by what factor do great designs last?  

Can great design be produced in a software factory?

The concept of a software factory has always seemed broken to me. The main idea of a software factory is to hire designers to create the right components, and hire less skilled people to assembly the components together to create new software systems. The appeal: you don't need so many smart creative people. The problem is that it doesn't work.

On the surface, it sounds great because you don't need so many software developers. And you hire less skilled (and less paid) workers to assembly the components like factory workers. But factory workers don't make design decisions on-the-fly during the manufacturing process. And assembly usually requires some code. The software factory metaphor is at least a little broken.

If you think about it, every line of code is a design decision not a manufacturing one. Coding is about making small little design decisions; one after another. So coding is a design process not a manufacturing process. Taking this further, the actual manufacturing is done by the compiler and build system.

Luckily, the cost of compiling and packaging is close to zero so why not do it as often as possible. We can constantly build what we have designed, then analyze and test the results.  The build process is our manufacturing process, so manufacture after every commit; manufacture at night; manufacture in the morning; keep manufacturing. It is as close to free as we can get.

So, if you want a better model for a software factory then think of one not composed of people, but robots. A software robot that constantly checks for design (code) changes and then performs the manufacturing (build) process; a robot for testing; a robot for shipping. One implication: if people (designers) aren't in the factory then they probably should not be put in a warehouse. Buy some robots instead.

Ultimately, the software factory is about shipping. If you use this model for the software factory, you will ship often and make your customers happy.

So, great design can be manufactured in a software factory as long as your factory consists of robots not people. Coding is easy if you do great design and great design is great code.

Keep designing.