News for hackers. Stuff that matters.
Re:The microservices cargo cult by aartur on Tuesday October 06, 2015 @06:55AM (#10338008)
Microservices are advertised as a means to modularization, but it's what programming language modules are for - they are defined on source code level and can be freely used in different runtime components without network/ops/version-management headaches. When you have your module defined that way, you can think of exposing it as a microservice because this may make sense for your use case.

Imagine that each Python module runs as a microservice. For many modules this would lead to huge performance degradation, for example a regexp module can be called thousands times per second, the running time of a call is usually short and replacing an in-process call with a network call will give 100-1000x slowdown.

But if you take a different use case of the same module - complex regexps running on large texts, potentially causing out-of-memory errors, then packing the module into a microservice can make sense - separate processes can have large caches, an out-of-memory error terminates an instance of a microservice only and not the calling process.

Generally I think the advice should be to always use source code modules in the first place, and create microservices using these modules for specific use cases only involving runtime needs like caching, fault tolerance, scalability.

Re:The microservices cargo cult by liotier on Tuesday October 06, 2015 @08:40AM (#10338410)
> Microservices are advertised as a means to modularization, but it's what programming language modules are for - they are defined on source code level and can be freely used in different runtime components without network/ops/version-management headaches. When you have your module defined that way, you can think of exposing it as a microservice because this may make sense for your use case.

Yes yes yes ! If your architecture and data model are funked up, then it doesn't matter how you implement them - you are screwed. On the other hand, proper modeling with separation-of-concern and well-defined interfaces will let you implement as anything you need, be it microservices or function calls inside a monolith.

Re:The microservices cargo cult by togusa on Tuesday October 06, 2015 @08:22AM (#10338318)
Most of the runtime needs in this space can be managed with circuit breakers without having to provide separate processes or memory spaces, be they temporal or resource based.

For example your regex, could be given 20ms to run and use a maximum of 8Mb of heap before it is interrupted. This can happen on a single thread and drop back to the caller if an exception is thrown. I'd love to see a language feature which defines the maximum stack and heap for a particular scope i.e. in C#:

   Breaker.Heap(8.MiB(), () => {
       Breaker.Time(200.Milliseconds(), () => {
           // risky operation
       });
   });
(we already do the time breaker, but not the heap)

Edit: correct calling convention.

Edit 2: add missing extension method brackets

Re:The microservices cargo cult by gregmac on Tuesday October 06, 2015 @09:53AM (#10338852)
Aside, for both the circuit breaker and numeric overloads, is that a particular library you're using or just example code?

By themselves, the overloads for integers like that is pretty neat, never seen that before. I can actually think of several dozen places I do things like TimeSpan.FromSeconds(x) where that could enhance readability.

Re:The microservices cargo cult by radicalbyte on Tuesday October 06, 2015 @02:31PM (#10341202)
I was thinking the same thing - Extention Methods on the types of common literals can make for some very pretty interfaces.

In combination with operator overloads and implicit casts and you have some really powerful tools for building readable APIs :)

Re:The microservices cargo cult by togusa on Tuesday October 06, 2015 @10:17AM (#10339025)
It's a real library I wrote. I just noticed I missed the brackets. Quick example you can infer the rest from:

Code:

    public static class IntegerExtensions
    {
        public static TimeSpan Minutes(this int val)
        {
            return TimeSpan.FromMinutes(val);
        }
    }

Usage examples I can think of:

   var eightMinutes = 8.Minutes();
   var tenMinutes = 8.Minutes() + 2.Minutes();
   DoSomethingEvery(8.Minutes());
Re:The microservices cargo cult by gregmac on Tuesday October 06, 2015 @10:34AM (#10339130)
Yeah I figured. Is it published/OSS?
Re:The microservices cargo cult by togusa on Tuesday October 06, 2015 @10:42AM (#10339180)
Not at the moment. I've got a ton of stuff I probably could publish however.
Re:The microservices cargo cult by jmcqk6 on Wednesday October 07, 2015 @10:53AM (#10346362)
Just a note, because I started in the same way you have, simply writing my own extension methods in a common dll. The Humanizer library has a bunch of these features, including the 6.minutes() functionality:

https://github.com/MehdiK/Humanizer

Re:The microservices cargo cult by Too on Tuesday October 06, 2015 @02:41PM (#10341301)
The latest version of .net actually has a built in timeout argument to the regex match function ;)
Re:The microservices cargo cult by togusa on Tuesday October 06, 2015 @03:04PM (#10341477)
Hadn't noticed that. Thanks for the pointer :)
Re:The microservices cargo cult by aartur on Tuesday October 06, 2015 @08:51AM (#10338470)
Interesting. Is the circuit breaker a feature of .NET running on Windows?

To my knowledge, it can't be implemented on Linux + Java or Python (a thread can't be terminated from outside, and some syscalls involve a whole process).

Re:The microservices cargo cult by togusa on Tuesday October 06, 2015 @10:21AM (#10339061)
It's a library I wrote.

The time breaker is actually quite complicated. It is a wrapper that sets up some global parameters on the thread for timeouts on async/await calls and handles the timeout conditions. It integrates with our own async wrappers for external http calls, message delivery, query execution etc. It only enforces that all aggregate async calls will complete or fail by the end of the timeout period. Realistically this is usually around the 500-800ms space as load spikes can break everything otherwise.

Re:The microservices cargo cult by Too on Tuesday October 06, 2015 @02:47PM (#10341353)
.net has a public thread.abort function which allows this, it will result in a interruptedexception on the aborted thread. I think there are ways to do this in java and python also although I know the official stance on thread.abort from the python maintainers is no way in hell.
Re:The microservices cargo cult by eonwe on Tuesday October 06, 2015 @09:34AM (#10338722)
I think this can be mostly implemented in Java with bytecode re-writing which will check for the conditions on time to time.

Stopping the thread can still leave some of the stuff in indeterminate state if the thread has some resources it needs to release manually.

Re:The microservices cargo cult by StavrosK on Tuesday October 06, 2015 @08:52AM (#10338473)
Very true, but I've heard modularization touted as a benefit of microservices many times, as if it's exclusive. You can get modularization as a first-class feature in your favorite language, and almost for free!
Re:The microservices cargo cult by SixSigma on Tuesday October 06, 2015 @09:18AM (#10338624)
What you're describing is an operating system.

Replace Microservices with Microkernel and you can read the Torvalds-Tannebaum debate instead [1]

http://www.oreilly.com/openbook/opensources/book/appa.html

Re:The microservices cargo cult by raverbashing on Tuesday October 06, 2015 @08:17AM (#10338296)
You're right, but sometimes modules != services

Your database is a service. You can't use multiple dbs depending on the situation.

If it can be replaced by multiple instances of the same module than yes, creating a microservice is probably stupid

Re:The microservices cargo cult by dmux on Tuesday October 06, 2015 @07:37PM (#10343179)
>they are defined on source code level and can be freely used in different runtime components...

To me, components and services are two completely separate abstractions. A component is a collection of code -- a module -- that can be duplicated and used in numerous different systems (much like a 5 ohm resistor). Updating a module in one system doesn't affect any other external system. Services on the other hand I think of as multi-tenant systems that are used to provide common functionality that is likely to change.

Re:The microservices cargo cult by pjmlp on Tuesday October 06, 2015 @07:34AM (#10338126)
Yeah, which just goes to show how microservices advocates understand programming.
Re:The microservices cargo cult by sre_ops on Tuesday October 06, 2015 @07:37AM (#10338135)
> magine that each Python module runs as a microservice. For many modules this would lead to huge performance degradation, for example a regexp module can be called thousands times per second, the running time of a call is usually short and replacing an in-process call with a network call will give 100-1000x slowdown.

This is absolutely irrelevant. If your call budget is 400ms then extra 4ms that it takes fetching a data from a micro service is negligible. Make 400ms 4ms and you are done.