58

Martin Fowler's book "Patterns of Enterprise Architecture" states: The easier question to answer is probably when not to use it. You probably don't need a Service Layer if your application's business logic will only have one kind of client - say, a user interface - and it's use case responses don't involve multiple transactional resources. [...] But ...


42

A service runs in the background, even if no-one is signed on to the machine. Anything you can imagine wanting to do without relying on a person to start an app and click a button is a good candidate for a service. For example, monitoring a folder and whenever a file is written to it, process it in some way. Any "server" you can think of - web server, ftp ...


34

Adding a service layer because you have evaluated the idea and concluded its the best approach: good Adding a service layer because that's what all the cool kids are doing: bad If your gut says you don't need one, then don't make one. One of the more disappointing developments in the programming world over the past 10 years or so is that it has become ...


22

There are many factors that go into the decision of creating a service layer. I have created service layers in the past for the following reasons. Code that needs to be re-used by multiple clients. Third party libraries that we have limited licenses for. Third parties that need an integration point into our system. Centralizing duplicated business logic. ...


22

In 'SOLID' the 'I' stands for Interface Segregation. The whole idea of this principle is to split large interfaces into smaller ones, more modular. In MVC service would normally have an interface that controller would rely upon. You don't want your controllers to know about concrete implementation of that service. Therefore, a bunch of services with one or ...


16

An anemic model is simply a data container. It doesn't contain behavior. (This might actually be considered a good thing in the functional paradigm.) The opposite of an anemic model is not a model injected full of domain services. You're describing two extremes -- both are bad. If you have an anemic model, you're not fully embracing what OOP offers. If you ...


15

Why do we even need it? You don't. Creating a separate database for each service helps to enforce domain boundaries, but it's only one approach. There's nothing stopping you from having all your services share the same database. As long as your services behave and don't do unexpected things to data owned by other services, you'll be fine. I don't know ...


14

I think the word 'service' gets bandied around so much that it's meaning nowadays is very overloaded and confusing. There is a big difference between a 'service layer' and a 'web service [layer]'. A 'service layer' is an abstraction behind which you put the business logic that will be consumed regardless of the UI. That way the UI layer can be as simple ...


13

Imagine you live in a small town and you have two supermarkets. The first one is across the street. You go there, you buy what you need, you pay for it, and you can leave with the products you've bought. The second one is outside the city. You have to use your car to go to it, then you have to find a free parking spot (the parking being small, you have ...


13

So there's my second question "What's the best way to design REST service code to support prior versions." A very carefully designed, and orthogonal API will probably never need to be changed in backward incompatible ways, so really the best way is not to have future versions. Of course, you probably won't really get that the first try; So: Version your ...


12

Yes. I have seen architectural diagrams of SOA (Service Oriented Architecture) where exactly this happens. A service should be written in such a way that it doesn't care if user is calling it, a service in the 'same layer', or it is being combined into a composite service. The Open Group SOA Reference Architecture diagram shows services calling services in ...


12

I was part of a team that successfully built a microservices architecture using a service bus. Initially, we believed that microservices and an event driven architecture would enable us to fix the underlying shared data ball-of-mud database. What we learned was that microservices and an event driven architecture required us to get rid of the underlying ...


11

The difference may be subtle between both. For example in .NET world, you may have an application which would feel like monolithic to an end user and which will work on a same machine, but inside, would be separated into a bunch of WCF services. You may also have architectures where libraries are not strongly linked (addins/plugins) and are just following a ...


9

Another advantage of services is that when you update the service, it is immediately deployed to all consumers of the service. So if you fixed a bug, or performance issue, everyone gets the benefit as soon as the updated service goes live, instead of having to distribute an update that people may choose to ignore.


9

Services on Windows are basically programs that run without a GUI. Web servers (such as apache), database servers (such as mysql & sql server), anti-virus engines, and application/'middleware' servers are all practical examples of applications that often run as services. There may be GUI client to allow you to interact with the service, but the service ...


8

Library Advantages: Lower overhead per call (only jump or even inlined) = may increase performance Simplest thing that could possibly work No risk of centralized service going down and impacting all consumers Service Advantages: Everyone gets upgrades immediately and transparently (unless versioned API offerred) Consumers cannot decompile the code Can ...


7

TL;DR Is it a good idea to use a kitchen-sink server for various services? There's no universally-correct answer to this question. It is fundamentally a business decision based on the budget you have and the problems you are trying to solve for. Arguments for Separating Services There are many reasons for separating services, but two of the biggest ...


7

It's not contradictory. Both proponents would like you to put your actual code in the domain object itself. ie. public class Order { private string status = "not bought"; public void Buy() { this.status = "bought"; } } vs ADM public class Order { public string Status = "not bought"; } public class BuyingService { public ...


7

Threads do have significant costs - VERY roughly - imagine 100K bytes per thread (they each need a stack for one thing), and they each place a slight burdon on operating system components (e.g. scheduler) which have to manage them all. Threads DO present a very simple model for managing async tasks. I'm a big fan of that approach. But if you are going to ...


6

Thoroughly construct and define an API, or set of different APIs if needed, then implement by just wrapping requests to this webapp (and/or packages which are used by this webapp). This will help you to "multithread" following development. You'll be able both build new tools, which will use your new API, and, at the same time, you can start gradually ...


6

Most Service Layers I've seen are a complete mess. Services tend to have a lot of different methods, 1500 LOC are not rare. The different methods have nothing in common, but do share code. This results in high coupling, low cohesion. It also violates OCP, because every time a new operation is needed, you have to modify the code instead of extending the code ...


6

Adding an interface (a service layer is a type of interface) takes time. A good one takes a lot of time to design and test. It is very important to get it right on the first try because changing it later breaks all the clients. Also, consider that you probably won't know what needs to be in that interface until you have a second client with slightly ...


6

I wouldn't say that a console application is totally different from a windows service. They are both hosts to execute code. That being said, there are some key differences: A service can run even if a user is not logged into the PC. A service can easily be configured to run in the context of a high-authority accounts such as Network Service or Local ...


6

Front end <--> API Service -> Service -> Repository -> DB Right. This's the basic design by segregation of concerns proposed by Spring Framework. So you are in the "Spring's right way". Despite Repositories are frequently used as DAOs, the truth is that Spring developers took the notion of Repository from Eric Evans' DDD. Repository interfaces will look ...


6

I know that these are two different methods but they are doing the same task No they aren't. One is linking a person to a company. The other links a company to a person. They may use the same implementation to achieve these two tasks, but they are not the same task. Let's assume though that the code in each method is identical. Is DRY violated? Yes, ...


6

It depends (but I guess for most real-world situations the answer is no, you risk to run into trouble). A general-purpose audit trail may collect data which, depending on the details, might be affected by laws of data security and privacy of the jurisdiction where your application will be used. If those laws will force you to keep the data only accessible ...


5

Service A program, routine, or process that performs a specific system function to support other programs, particularly at a low (close to the hardware) level. When services are provided over a network they can be published in Active Directory, facilitating service-centric administration and usage. I would like to know some practical ways in which ...


5

What you are describing is in fact a distributed transaction implementing two-phase commit. Some enterprise messaging platforms include transaction managers to support that kind of thing, but concrete products are platform / language dependent. I don't have concrete experience with such tools, but hope these pointers help.


5

In the MVC pattern, eberything that is not part of the Controller or View is considered to be part of the Model side of the triad. This means that from an MVC perspective, your question is moot, because both your services and models are part of the MVC Model side of the triad. As most MVC frameworks provide data access services as part of their Model ...


5

Do we need dependency injection in this case? It depends on what you try to accomplish. Dependency injection is needed in order to easily replace the underlying implementation. Common examples are: To replace actual implementation by stubs/mocks in a context of unit testing. To easily swap between several data access layers (for instance to deal with ...


Only top voted, non community-wiki answers of a minimum length are eligible