views:

55

answers:

4

Should caching, which is a cross cutting concern, be ever turned into a web-service?

The question might be a little weird, but I feel in SOA, a service should be identified based around a business solution, and we should not expose services whose only responsibility is to cache Objects. This does not seem to be a business function at all. If anything it seems like a performance improvement.

Should we ever introduce and implement a service just to cache data? Wouldn't that be a hindrance to thinking in terms of your domain model itself? I mean whenever you need an object to be cached within another service, you will have to move this class to the cacheService.

What is the general opinion about this?

+2  A: 

I don't think this is a very good idea, typically the concept of caching is to make data available and keep it closer to the point of usage. Moving this out to a true software as a service or other service model, in a traditional sense limits that ability.

Cache needs to be something fast, local and readily available.

Mitchel Sellers
A dedicated caching service can still be faster than using the database.
Matthew Flaschen
A cache that is closer to its use could would be faster
Aneesh
+3  A: 

I think improving performance for users is a business function. I think your question really is whether you should factor out your caching to a single service, or do it internally to other services. The answer, as always is, it depends. But it certainly can work to have a dedicated caching service. For instance, Google does this for memcache.

EDIT: Again, there's more than one way to skin a cat. BUt you don't necessarily have to cache the definitive Person object. Another possibility is to use the caching service for rendered data, say a PDF account statement. For instance, Hi5 (a social networking site), uses memcache to cache fully prepared user profiles.

Matthew Flaschen
How do I manage my domain model in this case. eg: Say hypothetically I have a Person class that never changes and I have an account class that constantly changes. I want to cache my person class which would now come out of a different service cos it is cached. How will the change to the account be persisted to the datbase (talking from an OO and ORM perspective).If I hadn't cached the Person class (or used the ORM's own cachine mechanism) I would have just looked up the Person through the ORM and updated the value of the account. And persistence would have been transparent.
Aneesh
A transparent write-thru cache is what you probably would want, and those are on the higher end of complexity as you can imagine. If you are using Java, have a look at Terracotta.
fuzzy lollipop
Yes ! Agreed. Thanks.
Aneesh
+1  A: 

if that service acts as a Facade to the previous non-cached service then yes, it could be "its own service". Especially for read-only or read-mostly data, this makes sense. But remember that caching like threading is a treacherous domain. It is easy to "do" but extremely difficult to do "correctly", and done incorrectly it can cause a ridiculous amount of problems that are difficult to debug and difficult to fix once you find the cause. Think about it this way, Content Distribution providers like Akamai built their entire business on providing caching as a service.

fuzzy lollipop
Absolutely agreed. As a facade, totally warranted. But my concern is mostly with regards to services that cache domain objects. Domain objects that really belong in some other service, but put into the caching service cos all caching is done by that service. So instead of being a facade this service ends up being consumed by the other services in order to lookup their domain objects.
Aneesh
a "Big old bucket of everything" anti-pattern should be avoided as a forward facing service. A "Big old bucket of everything" as a black box caching service on the back end might be a different story.
fuzzy lollipop
A: 

I would agree with your thinking that web services should expose business functionality. The idea of a cache web service seems like a bad idea.

Thinking about this from a usage perspective, what does this mean really? It seems to imply that clients would first hit the cache web service to get an object. If it's not there, they'd need to get it from the real web service then "push" the object back into the cache? That's asking a lot of a client. Any caching workflow should be transparent to the client.

If however your talking about backing some related web services with a cache that's "hidden" (and transparent) from the clients, used solely for the purpose to making the entire family of web services more responsive, then yes it might be a good idea.

Vinnie
To answer the first question, no the consumers would hit the real service. The real service has to hit another service to look up its own domain object because it is cached by that service. Now that means my domain object is split across two services already.I am not sure if I cleary understand what "backing related web servies with a cache" would mean. If you mean backing a real webservice with another webservice that provides caching, yes that is what I mean. But this webservice is not hidden from other clients. But it is possible that they choose not to hit it directly.
Aneesh
Two hops? Crazy. It'll die a latent death.
duffymo
If the clients are going to hit the real web service with that service hitting the cache, I don't really see the advantage of exposing the cache to anyone externally as a web service. For clients that choose to hit the cache ws directly, they will still need to go to the real ws on a cache miss. Why not just make all of that transparent to the client by not exposing the cache in the first place. You'll still have the benefit of caching with no added complexity to the client.
Vinnie
Yes. That makes sense. Thanks.
Aneesh