SOA architecture. Best strategy to support versions - wcf

He are having a debate about a proper way to support versions in SOA.
One option: is to implement all endpoints (Version/Contracts) in the same application in a strict manner. Thus supporting backward compatibility in the same application.
Second option: to create branches with single endpoint. Deploy each endpoint in a different application.
Each option has its pro/cons. Most of the sites I've notice support strategies in the same application (code base) strict/agile/flexible.
But there are also benefits to the second options. By breaking the endpoint to branches and different deployments each endpoint become more stable and detached from the others. Allowing developers to not consider backward compatibility when they write new functionality. I guess it also makes the 3rd party integration harder (changes to DB scheme etc.).
What do you think?

Definitely option 2!
To solve the DB issues you can use a repository for each micro service, and to avoid multiplicity, handle the generated ORM entities in a shred kernel.as i see it, the idea of a micro service is that it is a stand alone process, while if you go with the 1st approach you are coupling between services that are not related(NOT IN THE SAME DOMAIN => DDD) + the backward compatability issue, every time you want a fix you have to: or update all micro services, or ask the clients to update their side.
sincerely YBM

Related

Ember adapter and serializer

I'm building an Ember application with ember-cli and, as a persistence layer, an HTTP API using rails-api + Grape + ActiveModelSerializer. I am at a very basic stage but I want to setup my front-end and back-end in as much standard and clean way as possible before going on with developing further API and ember models.
I could not find a comprensive guide about serialization and deserialization made by the store but I read the documentation about DS.ActiveModelSerializer and DS.ActiveModelAdapter (which says the same things!) along with their parent classes.
What are the exact roles of adapter and serializer and how are they related?
Considering the tools I am using do I need to implement both of them?
Both Grape/ActiveModelSerializer and EmberData offer customization. As my back-end and front-end are for each other and not for anything else which side is it better to customize?
Hmmm...which side is better is subjective, so this is sort of my thought process:
Generally speaking, one would want an API that is able to "talk to anything" in case a device client is required or in case the API gets to be consumed by other parties in the future, so that would suggest that you'd config your Ember App to talk to your backend. But again, I think this is a subjective question/answer 'cause no one but you and your team can tell what's good for a given scenario you are or might be experiencing while the app gets created.
I think the guides explain the Adapter and Serializer role/usage and customization pretty decently these days.
As for implementing them, it may be necessary to create an adapter for your application to define a global namespace if you have one (if your controllers are behind another area like localhost:3000/api/products, then set namespace: 'api' otherwise this is not necessary), or similarly the host if you're using cors, and if you're doing with cli you might want to set the security policy in the environment to allow connections to other domains for cors and stuff like that. This can be done per model as well. But again, all of this is subjective as it depends on what you want/need to achieve.

Branching webservice api version

I'm working with my team on the "core" domain of our job, we have several DBs, Webservices, importer, etc... We expose the domain services to other teams through a backend WCF webservice. This webservice is cut in several api (or areas).
We deploy this on several production server (~ 80) (1 server <-> 1 customer).
Problem is: Some api goes public and we must maintain the same contract throught many releases. Others team want more flexibility (3 internal api contract version) as they can't follow our delivery rate (longer cycle)
Actually we are only serving this as a whole, and we are using a classic three branch branching (DEV/MAIN/RELEASE'n')
I'm trying to upgrade my TFS Team collection organization to handle a defined version range of each API version:
API Foo v2 (hxxp://-host-/api/foo/v2/...)
API Foo v3 (hxxp://-host-/api/foo/v3/...)
API Bar v1 (hxxp://-host-/api/bar/v1/...)
API Bar v2 (hxxp://-host-/api/bar/v2/...)
Currently we have the following branching schema:
$\MyTeamCollection
|___\DEV {Branch}
|___\Databases
|___\MyDBProj (SSDT)
|___\Documents
|___\MyWebService\MyWebSvc.Usage.docx
|___\Projects
|___\MyWebService.Core
|___\MyWebService.API.Bar
|___\MyWebService.API.Foo
|___\Shared
|___\MyDB\MyDB.DacPac, etc...
|___\MyWebService\MyWebsvc.Bar.Contract.Dll <-- WCF DataContract/ServiceContract
|___\MyWebService\MyWebsvc.Foo.Contract.Dll
|___\MAIN {Branch} <-- This one is what is on the integration server
|___\R1 {Branch} <-- This one went on a production server and is kept aside
|___\R2 {Branch}
|___\Archive
|___\R0 {Branch} <-- This one is obsolete but is archived here
Actually it handles a group of single api versioning. => Each release ship with a set of latest api version (Foo, Bar)
My question is how can I evolve this to handle multiple Api Version in each release (Foo-v1, Foo-v2, bar-v3, bar-v4)
Should i create branch inside branch? Won't this be a nightmare?
Any actual working teamcollection organization on your side?
Thanks,
-Jeremy.
Some additions:
All my clients are .Net, we provide them the assembly named MyWebsvc.Foo.Contract.Dll. This assembly contains:
ServiceContract interface which is implemented by a proxy pattern
[ServiceContract]
public interface IFooService {
Foo Get(int Id);
}
And all data contract needed (DTO + Serialization)
[DataContract]
public class Foo {
// ...
}
On the web service side there is the actual implementation
public class FooServiceImpl : FooApi.IFooService { ... }
For the purpose of this answer, I imagine that you have thoroughly reviewed the abundance of version control branching and merging guidance available online. As such, I suspect that the answer may not be found in “more” version control, but rather in a modest shift in the way features are enabled and available for customer use. Therefore, you may find that implementing a feature toggle solution will reduce the number of release versions that you need to maintain. The following article by Martin Fowler provides a good overview of feature toggles.
http://martinfowler.com/bliki/FeatureToggle.html
Our development team has utilized the concept of feature toggles, in our self-hosted WCF Windows Services, to provide a fully configurable set of endpoints that can be enabled/disabled (and adjusted) via configuration. In such scenarios, we typically utilize the customers’ data repository (database, ldap, etc) to store the configuration values and toggle switches, then when the service runs, it searches the repository for the configuration and then sets up and enables the interfaces in the manner the customer needs/wants.
Hope this helps.
Regards.
Jeremy,
there are a few questions you need to consider.
a) are your clients .Net as well or can they be in any technology? WCF has a really nice "compatible" versioning mechanism, but unfortunately it's non standard and only works with .Net clients
b) do you have the ability to give some guidance as to how the clients consume the services?
The only way to keep this problem under control is to adopt a "compatible" versioning strategy. As you pointed out, you want to have several (max 3) major releases in production and each time you evolve one or more major release you want to create a compatible (minor) version such that there is always one and only one release for each major version of the service running.
From a TFS perspective, I would consider each major version independent from each other, as in essence, they are somewhat independent services. I understand that creates a bit more work since you could have some update that applies to more than one major release, but IMHO, it's not worth the trouble to try to optimize that, unless you are actively working on all major versions simultaneously.
Achieving "compatibility" from one version to the next is not that hard, there are number of guidelines you want to follow both on the service side and the client side. I co-authored this article way back in 2008. http://www.infoq.com/articles/contract-versioning-comp2
I also wrote that blog post recently specifically for HTTP based APIs: http://www.ebpml.org/blog2/index.php/2013/04/13/formalizing-the-api-style
I want to emphasize that it's generally a good idea to use a minor version that is provided by the client to indicate which version of the service was in effect when it was built. The reason for that is that you can handle small breaking changes in a compatible way by knowing which minor version of the service it is compatible with. You still have a single release per major version and the variants are directly handled by the latest (minor) version of the service.
Versioning is key to a healthy API that allows clients to upgrade on their own terms (risk, budget, resources,...) and to the best of my knowledge, a "compatible versioning" strategy is the one that works best.

Moving MVC-style service layer under WCF

Recently I've been working with MVC4 and have grown quite comfortable with the View > View Model > Controller > Service > Repository stack with IoC and all. I like this. It works well. However, we're moving towards company wide application platform that will serve the majority of all business applications needs within the company.
Basic architecture goals:
Client facing MVC site
Internal Admin web site
Plethora of scheduled jobs importing/exporting data/etc to third parties
Service Bus sitting in the middle to expose business events
Public API for customer consumption
My initial thoughts are to introduce an "enterprise service layer" by applying my service interfaces to WCF contracts and registering the WCF proxy classes in my IoC. This would allow me to reuse the same pattern I'm currently using, butt I've not found a lot of examples of this in practice. Except this guy.
Admittedly though, I'm unsure what the best solution is for a project this scale.
1) What are the considerations when centralizing business services?
2) How does this affect cross cutting concerns like validation, authorization, etc? I thought I had that figured out already, but putting DTOs between the layers changes all this.
3) I'm experienced with WCF, but I hear Service Stack is all the rage...Should SS be a consideration with its RESTful goodness?
This guy here. I am not an expert in this area by any means, but hopefully I can provide a bit more context around things.
The main problem with using IoC to resolve WCF ChanelFactory dependencies as per my post is that the client also needs to have access to the service contracts. This is fine for a View > View Model > Controller > Service > Repository type architecture but is not likely to be possible (or desirable) for a shared public API.
In an attempt to cover your other questions:
1) Some of the concerns are already mentioned in your second question. Add to that things like security, discoverability, payload type (XML, JSON etc), versioning, ... The list goes on. As soon as you centralize you suddenly gain a lot more management overhead. You cannot just change a contract without understanding the consequences.
2) All the cross cutting stuff needs to be catered for in your services. You cannot trust anything that comes in from clients, especially if they are public. Clients can add some validation for themselves but you have to ensure that your services are locked down correctly.
3) WCF is an option, especially if your organisation has a lot of existing WCF. It is particularly useful in that it supports a lot of different binding types and so means you can migrate to a new architecture over time by changing the binding types of the contracts.
It is quite 'enterprisey' and has a bewildering set of features that might be overkill for what you need.
ReST is certainly popular at the moment. I have not used Service Stack but have had good results with Asp.Net Web Api. As an aside, WCF can also do ReST.
I've previously provided a detailed explanation of the technical and philosophical differences between ServiceStack and WCF on InfoQ. In terms of API Design, this earlier answer shows the differences between ServiceStack Message-based approach and WCF / WebApi remote method approach.
SOAP Support
ServiceStack also has Soap Support but you really shouldn't be using SOAP for greenfield web services today.
HTML, Razor, Markdown and MVC
ServiceStack also has a great HTML Story which can run on stand-alone own with Razor support as seen in razor.servicestack.net or Markdown Razor support as seen in servicestack.net/docs/.
ServiceStack also integrates well with ASP.NET MVC as seen in Social Bootstrap Api, which is also able to take advantage of ServiceStack's quality alternative components.

good practice: REST API as the interface between the interface layer and business layer?

I was thinking about the architecture of a web application that I am planning on building and I found myself thinking a lot about a core part of the application. Since I will want to create, for example, an android application to access it, I was already thinking about having an API.
Given the fact that I will want to have an external API to my application from day one, is it a good idea to use that API as an interface between the interface layer (web) and the business layer of my application? This means that even the main interface of my application would access the data through the API. What are the downsides of this approach? performance?
In more general terms, if one is building a web application that is likely to need to be accessed in different ways, is it a good architectural design to have an API (web service) as the interface between the interface layer and business layer? Is REST a good "tool" for that?
Sounds like you've got two questions there, so my answer is in two parts.
Firstly, should you use an API between the interface layer and the business layer? This is certainly a valid approach, one that I'm using in my current project, but you'll have to decide on the benefits yourself, because only you know your project. Possibly the largest factor to consider is whether there will be enough different clients accessing the business layer to justify the extra development effort in developing an API? Often that simply means more than 1 client, as the benefits of having an API will be evident when you come to release changes or bug fixes. Also consider the added complexity, the extra code maintenance overhead and any benefits that might come from separating the interface and business layers such as increased testability.
Secondly, if you implement an API, should you use REST? REST is an architecture, which says as much about how the remainder of your application is developed as it does the API. It's no good defining resources at the API level that don't translate to the Business Layer. Rest tends to be a good approach when you want lots of people to be able to develop against your API (like NetFlix for example). In the case of my current project, we've gone for XML over HTTP, because we don't need the benefits that Rest generally offers (or SOAP for that matter).
In general, the rule of thumb is to implement the simplest solution that works, and without coding yourself into a corner, develop for today's requirements, not tomorrow's.
Chris
You will definitely need need a Web Service layer if you're going to be accessing it from a native client over the Internet.
There are obviously many approaches and solutions to achieve this however I consider the correct architectural guideline to follow is to have a well-defined Service Interface on the Server which is accessed by the Gateway on the client. You would then use POCO DTO's (Plain old DTO's) to communicate between the endpoints. The DTO's main purpose is to provide optimal representation of your web service over the wire, it also allows you to avoid having to deal with serialization as it should be handled transparently by the Client Gateway and Service Interface libraries.
It really depends on how to big your project / app is whether or not you want want to go through the effort to mapping your DTO's to the client and server domain models. For large applications the general approach would be on the client to map your DTO's to your UI Models and have your UI Views bind to that. On the server you would map your DTO's to your domain models and depending on the implementation of the service persist that.
REST is an architectural pattern which for small projects I consider an additional overhead/complexity as it is not as good programattic fit compared to RPC / Document Centric web services. In not so many words the general idea of REST is to develop your services around resources. These resources can have multiple representations which your web service should provide depending on the preferred Content-Type indicated by your HTTP Client (i.e. in the HTTP ACCEPT HEADER). The canonical urls for your web services should also be logically formed (e.g. /customers/reports/1 as opposed to /GetCustomerReports?Id=1) and your web services would ideally return the list of 'valid states your client can enter' with each response. Basically REST is a nice approach promoting a loosely-coupled architecture and re-use however requires more effort to 'adhere' to than standard RPC/Document based web services whose benefits are unlikely to be visible in small projects.
If you're still evaluating what web service technology you should use, you may want to consider using my open source web framework as it is optimized for this task. The DTO's that you use to define your web services interface with can be re-used on the client (which is not normally the case) to provide a strongly-typed interface where all the serialization is taken for you. It also has the added benefit of enabling each web service you create to be called by SOAP 1.1/1.2, XML and JSON web services automatically without any extra configuration so you can choose the most optimal end point for every client scenario, i.e. Native Desktop or Web App, etc.
My recent preference, which is based on J2EE6, is to implement the business logic in session beans and then add SOAP and RESTful web services as needed. It's very simple to add the glue to implement the web services around those session beans. That way I can provide the service that makes the most sense for a particular user application.
We've had good luck doing something like this on a project. Our web services mainly do standard content management, with a high proportion of reads (GET) to writes (PUT, POST, DELETE). So if your logic layer is similar, this is a very reasonable approach to consider.
In one case, we have a video player app on Android (Motorola Droid, Droid 2, Droid X, ...) which is supported by a set of REST web services off in the cloud. These expose a catalog of video on demand content, enable video session setup and tear-down, handle bookmarking, and so on. REST worked out very well for this.
For us one of the key advantages of REST is scalability: since RESTful GET responses may be cached in the HTTP infrastructure, many more clients can be served from the same web application.
But REST doesn't seem to fit some kinds of business logic very well. For instance in one case I wrapped a daily maintenance operation behind a web service API. It wasn't obvious what verb to use, since this operation read data from a remote source, used it to do a lot of creates and updates to a local database, then did deletes of old data, then went off and told an external system to do stuff. So I settled on making this a POST, making this part of the API non-RESTful. Even so, by having a web services layer on top of this operation, we can run the daily script on a timer, run it in response to some external event, and/or have it run as part of a higher level workflow.
Since you're using Android, take a look at the Java Restlet Framework. There's a Restlet edition supporting Android. The director of engineering at Overstock.com raved about it to me a few years ago, and everything he told us was true, it's a phenomenally well-done framework that makes things easy.
Sure, REST could be used for that. But first ask yourself, does it make sense? REST is a tool like any other, and while a good one, not always the best hammer for every nail. The advantage of building this interface RESTfully is that, IMO, it will make it easier in the future to create other uses for this data - maybe something you haven't thought of yet. If you decide to go with a REST API your next question is, what language will it speak? I've found AtomPub to be a great way for processes/applications to exchange info - and it's very extensible so you can add a lot of custom metadata and yet still be eaily parsed with any Atom libraries. Microsoft uses AtomPub in it's cloud [Azure] platform to talk between the data producers and consumers. Just a thought.

WCF - Domain Objects and IExtensibleDataObject

Typical scenario. We use old-school XML Web Services internally for communicating between a server farm and several distributed and local clients. No third parties involved, only our applications used by ourselves and our customers.
We're currently pondering moving from XML WS to a WCF/object-based model and have been experimenting with various approaches. One of them involves transferring the domain objects/aggregates directly over the wire, possibly invoking DataContract attributes on them.
By using IExtensibleDataObject and a DataContract using the Order property on the DataMembers, we should be able to cope with simple property versioning issues (remember, we control all clients and can easily force-update them).
I keep hearing that we should use dedicated, transfer-only Data Transfer Objects (DTOs) over the wire.
Why? Is there still a reason to do so? We use the same domain model on the server side and client side, of course, prefilling collections, etc. only when deemed right and "necessary." Collection properties utilize the service locator principle and IoC to invoke either an NHibernate-based "service" to fetch data directly (on the server side), and a WCF "service" client on the client side to talk to the WCF server farm.
So - why do we need to use DTOs?
Having worked with both approaches (shared domain objects and DTOs) I'd say the big problem with shared domain objects is when you don't control all clients, but from my past experiences I'd usually use DTOs unless it development speed were of the essence.
If there's any chance that you won't always be in control of the clients then I'd definately recommend DTOs, because as soon as you share your domain objects with someone else's client application you start tying your internals to someone else's dev cycle.
I've also found DTOs useful when working in a versioned service environment, which allowed us to radically change the internals of our app but still accept calls to the old versions of our service interfaces.
Finally, if you have a lot of client applications it might also be beneficial to use DTOs as you're then protected with an easily versionable service.
In my experience DTOs are most useful for:
Strictly defining what will be sent over the wire and having a type specifically devoted to that definition.
Isolating the rest of your application, client and server, from future changes.
Interoperability with non-.Net systems. DTOs certainly aren't a requirement, but they make it easier to design "safe" types.
In your scenario these design features may not matter that much. I've used WCF with both strict DTOs and shared Domain Objects and in both scenarios it worked great. The only thing I noticed when sending Domain Objects over the wire was that I tended to send more data (and in unexpected ways) then I needed to. This was likely more due to my lack of experience with WCF than anything else; but it's something you should definitely be wary of should you choose to go that route.