Showing posts with label SOA. Show all posts
Showing posts with label SOA. Show all posts

Friday, February 8, 2008

Designing a RESTful API

There's a bit of art that goes into designing any API. We've designed and refined a SOAP API over the last couple of years, and the RPC-like nature of SOAP does seem to make things fairly simple from an API designer's perspective. Everything looks more or less like methods you would see in C#, only exposed through a service.

Designing a RESTful API, on the other hand, is a process I am finding to be a much bigger mental leap.

The REST model is best suited for problems where you're dealing with assets - that is, things that you act upon. But I couldn't find any good examples that were truly RESTful and also handled complex asset scenarios.

What is truly RESTful? Well, to be truly RESTful you use all 4 HTTP verbs (GET, PUT, POST, DELETE). You don't add action verbs as params (?name=smith&action=delete). I could be flip and say it's not RESTful because it's cheating, but it's not about a dogma. The design criteria was to make the API as simple as possible, and having to know about special action= parameters requires additional knowledge on the part of the consumer. For us, the consumer should be able to have no prior knowledge of the API, just of the resources they want to access, and still be able to accomplish useful work.

The complex asset scenario is trickier, I think. Most of the RESTful APIs out there deal with rather flat and simple resource structures. Amazon's S3 resource structure never gets more complex than GET /[bucket-name]/[key-name], and Google's search API is also flat but decorated with lots of filters: GET /search?q=bill+material&output=xml&client=test&site=operations

Don't get me wrong - simple is good! It's just that these aren't great models to learn from for a more complex set of assets. For example, say I have a taxonomy of categories with n numbers of subcategories. Each category can contain n number of items. Items can also contain subitems. Categories and items can each have a set of properties, and furthermore each category and item can be one of a certain set of types, which means they can have different property sets. And the same items can appear in more than 1 category. In some cases I only want to retrieve a subset of all available properties for n items or categories.

Category A (categoryType=F1)
.|- Category AA (categoryType=G4)
....|-Item 27 (itemType=9H)
....|-Item 492 (itemType=4Y)
.|- Item 1 (itemType=9H)
Category B (categoryType=F1)
Category C (categoryType=F1)
.|-Category CC (categoryType=H8)
.|-Category CD (categoryType=H8)
...|-Item 1 (itemType=9H)
.....|-Item 303 (itemType=7T)
.....|-Item 305 (itemType=7T)
.....|-Item 306 (itemType=7T)
.|-Item 27 (itemType=9H)

This is, in a nutshell, the set of resources I need to be able to expose through the API.

For something with this level of complexity, where thinking in terms of sets becomes more natural, I found Microsoft's Astoria project (officially: ADO.NET Data Services) to be very helpful. Especially the concept of filtering resources.

Take the following example: GET /Customers[ALFKI]/Orders[1]/Employees, which filters the assets based on the data in the brackets, in this case returning those employees who created Order ID=1 for customer ID=ALFKI. The beauty of this approach is that it's easy to extend the filters in the brackets. So I could do GET /Customers[ALFKI]/Orders[1,2,9]/Employees or even /Customers[ALFKI,PDX,MSTR]/Orders[1-1000]/Employees.


The RESTful API we're working on isn't done yet - we're just starting to create a mock service that spits out static XML so we can get a feel for how the various consumers will actually use the API. This will let us play with the details of the API and the XML format before we commit to building all the data plumbing underneath it.

Here are some RESTful resources I found helpful:
  • Using ADO.NET Data Services - some great thinking from Microsoft on building a RESTful API for selecting complex data sets
  • Why REST Failed - the title is overstated, but Elliotte Rusty Harold (no relation to me) does a great job explaining the current challenges with PUT and DELETE support in modern browsers. Good for understanding what you're getting into.
  • Why PUT and DELETE? - an interview with Elliotte Rusty Harold that does a nice job of explaining why you want to go to the effort of supporting all 4 HTTP verbs despite the limited browser support. In a word - elegance.


Friday, December 14, 2007

Microsoft forecast: partly cloudy

In a previous post I asked Where is the Microsoft cloud? That is, where is the Microsoft competitive offering to Amazon's AWS, for example.


So far, I've found mostly hot air. BizTalk Services is interesting, but still very much in the early stages. Certainly worth keeping an eye on. But branding it under the BizTalk name seems very odd - these are fundamental services like authentication, access control, & connectivity - and not tied specifically to BizTalk.


I have to say that I'm not getting the great sense of urgency from Microsoft about cloud computing that Nick Malik's "Microsoft is coming" bravado suggests.

Now, Microsoft is certainly talking a lot about cloud computing - has been for the last 6 months. From a NetworkWorld article:
Microsoft also plans later this year to launch Version 1 of a 12- to 24-month project to create Windows Live Cloud Infrastructure Services, Web-based services such as directory, identity and storage. The operating system services target companies and developers, who will wrap them around their applications, such as tapping an online directory service to generate a Kerberos ticket that a user would present to gain access to an on-premises or service-based application.

Which all sounds like goodness. But that article was written in July. End of the year is only a couple of weeks away. Did I miss that Version 1 release announcement? Maybe they were talking in Friedman Units.

Can a project of this magnitude be even only 24 months away when Cloud Infrastructure Services is still just a Microsoft research project with a rather nebulous vision?

And if putting announcements with titles like "Microsoft Does Have a SOA Strategy" on your main SOA page is meant to inspire confidence, well...

Thursday, December 13, 2007

When a service isn't the answer

I was discussing a rather involved design issue with a colleague recently, and as I pulled away from the diagram I had drawn out as we were talking it over, I said, "Surely someone else has already dealt with these issues. There must be a 3rd party service we could use that would handle all of this for us."

"There is," my colleague said, "but they'll charge for every transaction, which can't be written off. If we build it ourselves then the costs are a capital expense and the cost can be depreciated."

And so it goes.

Monday, December 10, 2007

Distributed state management for ASP.NET

The more I delve into distributed architectures, the more I'm feeling like Microsoft just isn't providing much of a path forward to scalable distributed systems. Case in point: state management.

By default, session state in ASP.NET is stored in the web server's memory. To share state across servers - which you would want to do in a server farm - you need to store it in SQL Server or in the .NET state service. This is fine for small solutions, but once you bump up against the need to partition state across many servers or multiple hosting locations, things start to get complex and expensive.

Now, it seems the Java folks have worked through these issues already. Here I'm thinking of Space-Based Architecture and more concretely JavaSpaces.

Perhaps I'm oversimplifying, but wouldn't JavaSpaces be a perfect place to store session state in a distributed system? Data in a JavaSpace is persistent, atomic, distributed, & fault tolerant.

There isn't a .NET equivalent of JavaSpaces. But, MS does provide SessionStateStoreProviderBase and the ability to choose a custom provider for session state.

So, here's the recipe as I see it:
  1. Set up a JavaSpaces instance on a Linux cluster (probably using Blitz to start out with)
  2. Write a custom state provider that inherits from SessionStateStoreProviderBase and implements the necessary JavaSpaces methods. (Working out the bridging between .NET & JavaSpaces, of course. There is a tantalizing page called Using JavaSpaces from .NET - but it relies on a commercial product to accomplish this.)
  3. Change your ASP.NET web.config to point at your new custom state provider.
These don't appear to be big hurdles to overcome, and it seems like a nice little open source project.

(In the interest of due diligence, I did run across 2 commercial software products that seem to be solving this kind of problem: ScaleOut and NCache. But for a server farm of 20 servers, you're looking at something in the neighborhood of $30K, not including the cost of the Windows Server licenses + ongoing annual maintenance fees. There is also GigaSpaces, which provides hosted JavaSpaces and has a .NET API, but is also expensive.)


Here are some links I found useful in my research:

Tuesday, December 4, 2007

Where is the Microsoft cloud?

I've been doing heavy research lately into scalable distributed systems, and Amazon's S3 and EC2 are front and center in my brain as I'm working my way through the literature.

Amazon's AWS and now IBM's BlueCloud are out in front with cloud computing offerings. Google may or may not be planning something akin to S3 with Google shared storage combined with APIs.


In the midst of my research, I saw that Microsoft has a codename - Oslo - for their next iteration of SOA tools. And so the obvious question (to me, at least) is: where is Microsoft's cloud computing offering?

Well, looks like BizTalk Services may be Microsoft's response. Charles Young has an overview of his early experiences with it.

Looks like I have more research to do...

Wednesday, November 28, 2007

SOA for SAP

SAP has an interesting message on SOA, if I'm reading Joe McKendrick right on this - you can use SAP's SOA methods while starting out small as a subscriber to their SaaS offering, and then scale up to their enterprise offering later, in what would certainly be advertised as a "seamless transition."

This is precisely the sort of thing that a consistent architecture should allow. Of course, it cuts both ways - you could also (theoretically) move from SAP's enterprise offering to their SaaS offering. Or more interestingly, move to a competitor who offers the same set of SAP-compatible methods.

What, exactly, would prevent Oracle from offering a set of SAP-compatible methods? And who will be the first to try to claim intellectual property rights on a URL? Is http://mycompany.com/services/sap/adduser© right around the corner?

Once there is a significant set of companies who have committed to a particular vendor's SOA methods, they're also primed for another vendor to come sniffing around with a translation layer and lower pricing.

Saturday, November 24, 2007

Services & Volatility

Quick and dirty isn't what you normally think of wrt architecture, but sometimes it's useful to keep from getting caught in the weeds for too long. In short:
  1. Define your information model
  2. Define your abstract model (the business objects, as I think of it)
  3. Define your services and their bindings to the information model
  4. Define your processes and their bindings to the services - paraphrasing here, as the language is a bit vague.
(from David S. Linthicum's Reference Models and Architectures via James McGovern)

Key point is this: "The core idea here is to place volatility into a single domain, or a place where the use of services (and thus the information) can be defined, and redefined, according to the requirements of the business."

And that's my jumping-off point.

Traditionally this volatility domain has been in application logic (stored procedures, business logic code, and inevitably UI code). My thinking has been moving towards the idea of pushing that volatility domain more to the services. Not the data & transactional services that Linthicum defines as being part of step 3 above. But rather to move the business processes into workflows accessible to the business as services. This would avoid multiple constituencies having to independently wire up the underlying services (data & transactional) and ensure that everyone is using a consistent workflow.


I see challenges with this approach though...

First challenge is that workflows imply that state is being kept because they are asynchronous. You can hand a token to the client that will later let the client pull up the workflow in its current state. But now the client has to store and track that token itself, and handle situations where the state returned from the service isn't what was expected. Maybe I'm expecting too much here, but if you're going to go to the effort of making the workflow consistent across the business, then you really want to do it from end to end.

Maybe a solution would be to use webparts that front the workflow service. Here you would wrap the workflow service in a UI and keep it self contained, leveraging the ability of the webpart to share data with other webparts. And so consumers are stringing together common webparts that they organize in a way that makes sense for their part of the business.

Second challenge is handling the inevitable change that occurs in those workflow services. Maybe you can solve this with versioning for 80% of the consumers, and the rest of the consumers we have to accept have their own specific needs that aren't going to be met by the workflow services and this population of consumers will have to wire up their own specific code against the data & transactional services.

So, webparts (at least in a Microsoft world) fronting workflow services. It's not a bad approach, but those webparts are going to start getting complex... not sure we haven't just traded one problem for another. But still, there just might be something here worth pursuing....

Wednesday, November 14, 2007

Guerrilla SOA is to BDUF as the Internet is to...

Joe McKendrick's post on guerrilla SOA services describes services arising as islands or neighborhoods. Both are nice analogies.

But what does EA even mean in a world of guerrilla SOA? Extending the neighborhood analogy, do you have to burn everything down occasionally in order to get a coherent system? I'm thinking specifically of the experience of navigating my hometown Chicago's post-fire grid system vs. Boston's decentralized and unplanned road system.

Still, I find the guerrilla SOA concept rather compelling. What I like about this approach is:
  • It doesn't require perfection up front
  • Keeps the focus on the business
  • Abstracts the type system (WSDL) out to a format that can change without breaking clients. The Soya project would be a concrete example of this message-oriented format.