Skip to main content

SOA Done Badly vs SOA Done Right

I was under the assumption I had been doing SOA for over 3 years. Previously I have had services which did stuff, these talked to other services which did other stuff and so on. We would group services around functionality.

We would break these services down if they got too big to handle. Behind the scenes the services would talk to a single database. When it came to creating an application or system, these front end applications would invoke various services, which in turn invoked other services. This layered style of architecture worked for a while, so everything appeared to be fine.

The overall architecture looked like this:

Bad example of SOA

Over time I began to question the benefit of this style.

  • I spent more time coding than solving business problems
  • I spent more time debugging than solving problems
  • I spent more time fixing broken deploys than solving problems
  • I spent more time writing infrastructure (to glue services together) than solving problems

It turns out this is actually quite a common style to SOA. But there are some serious flaws with this layered approach.

Problems

  • If a service fails, the whole system is pretty much broken.
  • If the database breaks, the whole system is pretty much broken.
  • If a service is slow or breaks SLA, the whole system is pretty much broken.
  • In order to decouple between services, you need complex, costly abstractions.

Solution

A solution to solve these problems is to partition the domain boundaries, vertically. The overall architecture would look like this:

Good example of SOA
Details
  • Each domain could consist of one or more "services".
  • Each with their own choice of data store, e.g. SQL, NOSQL, file system etc...
  • No domain can directly communicate with another domain.
  • If they do need to communicate, then the pub/sub model would be used or an ansyc command could be issued. Think .NET events or the event design pattern but across processes, not objects.
Benefits
  • Each service could fail and the impact would be minimal, simply rollback the deploy or fix the problem. Once the service comes back to life any commands or events that have not yet been processed would be handled. Each service would have their own message queues to persist commands/events.
  • Services could be re-wrote and distributed easily, proving they are highly decoupled.
  • No complex infrastructure, e.g. no need to map between objects because the service owns the whole stack. The same model could be used across partitions for example.
  • Works really well with agile development methodologies, e.g. vertical slicing of stories.

There is more to this introduction. Microservices are a hot new topic. Being defined as "SOA done correctly". Using the second example, within each domain there could be multiple services (or autonomous components) that coexist. The likes of UI composition to enable applications to be created from services is another great benefit. This enables so called "mashups".

I'll expand on these topics over time, but I am certain this method of vertically slicing services based upon business capabilities will be my default approach going forward.

Comments

Popular posts from this blog

Constant Object Anti Pattern

Most constants are used to remove magic numbers or variables that lack context. A classic example would be code littered with the number 7. What does this refer to exactly? If this was replaced with DaysInWeek or similar, much clarity is provided. You can determine that code performing offsets would be adding days, rather than a mysterious number seven.Sadly a common pattern which uses constants is the use of a single constant file or object. The beauty of constants is clarity, and the obvious fact such variables are fixed. When a constant container is used, constants are simply lumped together. These can grow in size and often become a dumping ground for all values within the application.A disadvantage of this pattern is the actual value is hidden. While a friendly variable name is great, there will come a time where you will want to know the actual value. This forces you to navigate, if only to peek at the value within the constant object. A solution is to simple perform a refactor …

Three Steps to Code Quality via TDD

Common complaints and problems that I've both encountered and hear other developers raise when it comes to the practice of Test Driven Development are: Impossible to refactor without all the tests breakingMinor changes require hours of changes to test codeTest setup is huge, slow to write and difficult to understandThe use of test doubles (mocks, stubs and fakes is confusing)Over the next three posts I will demonstrate three easy steps that can resolve the problems above. In turn this will allow developers to gain one of the benefits that TDD promises - the ability to refactor your code mercifully in order to improve code quality.StepsStop Making Everything PublicLimit the Amount of Dependencies you Use A Unit is Not Always a Method or ClassCode quality is a tricky subject and highly subjective, however if you follow the three guidelines above you should have the ability to radically change implementation details and therefore improve code quality when needed.

DRY vs DAMP in Tests

In the previous post I mentioned that duplication in tests is not always bad. Sometimes duplication becomes a problem. Tests can become large or virtually identically excluding a few lines. Changes to these tests can take a while and increase the maintenance overhead. At this point, DRY violations need to be resolved.SolutionsTest HelpersA common solution is to extract common functionality into setup methods or other helper utilities. While this will remove and reduce duplication this can make tests a bit harder to read as the test is now split amongst unrelated components. There is a limit to how useful such extractions can help as each test may need to do something slightly differently.DAMP - Descriptive and Meaningful PhrasesDescriptive and Meaningful Phrases is the alter ego of DRY. DAMP tests often use the builder pattern to construct the System Under Test. This allows calls to be chained in a fluent API style, similar to the Page Object Pattern. Internally the implementation wil…