Uber's Michelangelo vs. Netflix's Metaflow

  Uber's Michelangelo vs. Netflix's Metaflow Michelangelo Pain point Without michelangelo, each team at uber that uses ML (that’s all of them - every interaction with the ride or eats app involves ML) would need to build their own data pipelines, feature stores, training clusters, model storage, etc.  It would take each team copious amounts of time to maintain and improve their systems, and common patterns/best practices would be hard to learn.  In addition, the highest priority use cases (business critical, e.g. rider/driver matching) would themselves need to ensure they have enough compute/storage/engineering resources to operate (outages, scale peaks, etc.), which would results in organizational complexity and constant prioritization battles between managers/directors/etc. Solution Michelangelo provides a single platform that makes the most common and most business critical ML use cases simple and intuitive for builders to use, while still allowing self-serve extensibi...

Adapter Design Pattern

The adapter pattern is an extremely useful pattern for a few reasons. The reason I like it so much is because if you understand it, then you understand the concept of Dependency Inversion (the "D" in SOLID object-oriented design).

Dependency Inversion is an object-oriented principle which states that in code, higher level modules should not depend on lower level modules. Instead, lower level modules should depend on higher level ones. Let's say you've got one higher level object that requires a lower level object to do it's job. But the lower-level object is likely to change or be swapped out for another. Here's the bad way to do it:

namespace HigherLevelModule
{
    public class HigherLevelObject
    {
        ......

        public void Run()
        {
            LowerLevelObject obj = new LowerLevelObject();
            
            string result = obj.GetSomething();
            Console.WriteLine(result);
        }
    }
}

namespace LowerLevelModule
{
    public class LowerLevelObject
    {
        ......

        public string GetSomething()
        {
            return new String("you got me!");
        }
    }
}



Now, the reason that this is bad, is because it makes the task of swapping out the lower level object more difficult than it needs to be. The higher level depends on the lower level! LowerLevelModule can be compiled without HigherLevelModule but not vice versa - which is the opposite of what we want.

So here's a better version:

namespace HigherLevelModule
{
    public class HigherLevelObject
    {
        ......

        public void Run()
        {
            IAdapter obj = LowerLevelObjectFactory
                                .GetInstance()
                                .GetLowerLevelObject();
            
            string result = obj.GetSomething();
            Console.WriteLine(result);
        }
    }

    public interface IAdapter
    {
        string GetSomething();
    }

    public class LowerLevelObjectFactory
    {
        private static LowerLevelObjectFactory Factory =
                                new LowerLevelObjectFactory();
        
        private LowerLevelObjectFactory()
        {
        }

        public static LowerLevelObjectFactory GetInstance()
        {
            return Factory;
        }

        public IAdapter GetLowerLevelObject()
        {
            return new LowerLevelObjectA();
        }

    }
}

namespace LowerLevelModule
{
    public class LowerLevelObjectA : IAdapter
    {
        ......

        public string GetSomething()
        {
            return new String("you got A!");
        }
    }

    public class LowerLevelObjectB : IAdapter
    {
        ......

        public string GetSomething()
        {
            return new String("this time you got B!");
        }
    }
}

With this new code, the higher level doesn't care what the actual type of the ILowerLevel instance is, it just cares that it has a GetSomething() method, which is guaranteed by the ILowerLevel contract. Now the higher level can use the factory method to create lower level objects all over the place, and if the type of the lower level object ever has to be changed, there's only one line of code that needs to be changed:

public IAdapter GetLowerLevelObject()
{
    return new LowerLevelObjectB();
}


Now THAT's maintainability. Wurd.

Comments

Popular posts from this blog

ChatGPT - How Long Till They Realize I’m a Robot?

Architectural Characteristics - Transcending Requirements

Laws of Software Architecture