https://app.ourcompany.com/somepage.html
https://app.ourcompany.com/someresource/id
There seem to be more potential trade-offs here than I can quite keep track of:
Since it's the same functionality, there's lots of opportunity for sharing: database, models, object caches, authentication, sessions, yadda yadda yadda. But some things have no need of sharing, or might even conflict with it: special developer token access, mixed-model authentication, etc.
"Really simple" implementation (all on one box) is just asking for trouble; "darn simple" implementation (app.ourcompany.com and api.ourcompany.com) seems better adaptable to the vagaries of internet traffic; "realistic" implementation, with load balancers and pools of servers and such is probably cheaper (less hardware) if there's only one hostname / pool of resources.
What if we want to rehost the API at a service like Apigee (I know you guys are listening ;-)? Does entangling the API URL with the app URL complicate that?
Jack Repenning
And the next thing you know, you're sucking down Darjeeling with Marie Antoinette and her little sister!
Database: can be on a remote machine anyway, so you could share this pretty easily.
Models and caches: at high levels of scale you probably want each host to have its own cache anyway. So the only thing to share is the code. Not really that much cost to lose the sharing at low usage levels.
Identity and sessions: this you do want to share. You'll need to find a solution. But single-sign-on is a solved problem. Auth, as you point out, will be different for the two endpoints, but identity should probably share.
So I wouldn't worry too much about the downsides of splitting the URLs.
Arlo
> You can get a lot of the sharing you mention without necessarily being on the same URL.
The argument specifically being made in favor of consolidation is code-sharing and deployment-machinery-sharing, more than runtime data sharing of various sorts: a single check out, yields one copy of a given model source code file, a single copy of the unit tests that protect api-developers from mistakes by app-developers and vice versa, and a single "deploy me please" button.
Jack Repenning
Most of the systems i have been involved with have used the same code
base to implement both the api and html pages. This does provide
immense benefits, as you mentioned above, when it is feasible (and it
almost always is). In my experience there is a huge upside, and no
significant downside, to implementing both the api and html pages in a
single code base.
(Most of the time i even use the same uris for both the html and api
resources. The content negotiation support in RoR makes doing so quite
easy. OTOH, if you want them to have separate uris the rails router is
easily capable enough to allow it without requiring any duplication of
code.)
The deployment question is less clear cut. I alway use a single
deployment for both html pages and the api, but i can imagine some
scenarios where it might be advantageous to segregate the different
work loads. Practically speaking, though, the additional operational
complexity of having separate deployments for html pages and the api
would rarely be worth it. I'd suggest a single deployment doing both.
You can always split the deployments later if there is ever data
suggesting that it would be beneficial.
Peter
barelyenough.org
After all, I assume you're already doing this - you have local dev build, a staging or test environment, and the liver server, right? It's pretty simple to add a couple new servers to the deploy script.
I wouldn't use a cost reason to justify either approach. Both are low cost and allow sharing (especially of static resources such as source).
So make the choice based on the value axis. Which would your customers (end users, programmers of client apps, etc) prefer? They don't care about your costs at all, so what would they like and why?
Arlo
along w/ saving some repetitive tasks, using the same component layer
for all interfaces makes it much more likely that the various
client-facing implementations exhibit the same business rules.
the exact details of the public identifiers (URIs) for resources are
left to the various front-facing connectors; as long as they are
consistent within the connector-space, that's fine. that said, i
usually try to follow a human-friendly convention of exposing the
mobile interface using m.{primary-domain}.com and the api interface
at api.{primary-domain}.com.
mca
http://amundsen.com/blog/
http://twitter.com@mamund
http://mamund.com/foaf.rdf#me
I do this all the time and, in my experience, it works quite well. It
might make exploring the api a tad non-obvious for some people so just
make sure you show now to pass the appropriate accept header with
curl, etc in your docs. A downside of this approach is that it could
complicate a transition to having separate deployments of the HTML app
and the API.
Peter
barelyenough.org
Cheers,
Mike
--
Mike
http://twitter.com/mikekelly85
http://github.com/mikekelly
http://linkedin.com/in/mikekelly123