TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

API-first architecture, or the fat vs. thin server debate

71 点作者 maus80超过 11 年前

10 条评论

jacques_chester超过 11 年前
I remember when this sort of thing used to be called SOA. Before that there was n-tier, before that client-server, before that people used to talk about terminals.<p><pre><code> What has been will be again, what has been done will be done again; there is nothing new under the sun. </code></pre> The best place to park different parts of the logic varies according to the algo-economics of the day. Right now people have fast client environments, so the balance is tipping back to heavy clients.
评论 #6544394 未加载
评论 #6545883 未加载
NathanKP超过 11 年前
One massive advantage of the API first architecture that wasn&#x27;t mentioned in this article is that it makes proper unit testing much easier because of the clear distinction between the server side API code and the client side JavaScript&#x2F;Mobile app.<p>Of course it is possible to test a &quot;fat&quot; server that does view and presentation logic, but it is much easier and more efficient to test a thin server and have a separate suite of tests for the client side app.
评论 #6544303 未加载
评论 #6544554 未加载
joshfraser超过 11 年前
One of the biggest benefits I see to API-first is that it encourages you to document everything well, and that process usually leads to better organization and greater consistency.<p>As far as fat vs. thin, I worry that this article could be a bit misleading. It&#x27;s great if you have an API that responds in 20ms as very few people can achieve that. But it doesn&#x27;t matter much in a world where mobile network latency can easily be 200-500ms. If you&#x27;re worried about app performance, I&#x27;d focus first and foremost on the number of requests you are making and making sure none of them are blocking. The network is the slow part. I know a lot of companies with blazing fast API&#x27;s and sluggish apps, because they&#x27;re optimizing the wrong thing.
评论 #6544561 未加载
PLejeck超过 11 年前
The article makes the implication that MVC is inherently slow. It&#x27;s not, in fact it can be quite fast if you use the right framework.<p>I&#x27;m assuming they only know that Rails is slow (which it can be, especially for a case where caching can&#x27;t help much like in an API) and assume that&#x27;s because of MVC and not because Rails is monolithic and Ruby-based.<p>Before I used Rails, I used an MVC consisting of Mongoose + Handlebars + Express in Node.js, and I regularly had pages render in under 10ms. The biggest bottleneck was consistently the communication with MongoDB, something I had very little control over.<p>So to conclude, stop blaming the architecture, start blaming the frameworks.
评论 #6546139 未加载
评论 #6544878 未加载
pearjuice超过 11 年前
Please note that the thin server should never be too thin. Logic should always happen in the server domain, handle the client as merely a presentation unit.
评论 #6544425 未加载
评论 #6544893 未加载
AYBABTME超过 11 年前
This article suggest that MVC implies a fat server, and that using newer patterns with thin servers breaks away from MVC.<p>Using a thin server with a Javascript heavy app basically means keeping the Model&#x2F;Controller on the server, then having Views&#x2F;Controllers on the client.<p>So in the end, you&#x27;re still with a MVC pattern, you just spread your Controller over two machines with RPC in between.
评论 #6545000 未加载
ubersoldat2k7超过 11 年前
In my last three projects we&#x27;ve aimed at an API first approach, and the flexibility of having the same API serve content for web or native mobile apps is the biggest win. We used Play on two of this projects and Jersey for another and the speed is very slow at first since the browser has to load a bunch of JS (AngularJS in this case) but then, the whole user experience is seamless. Our biggest problem with this approach were localization and authentication&#x2F;session handling. Tackling this problems were hard at first and I&#x27;ve never felt confident about the solutions we did for them, specially for authentication.
jamesmccann超过 11 年前
This is a good description of the difference between available architectures, but more detail is probably required to backup some of the discussion points, beyond the fact that reducing presentation is beneficial for response times. An API server is still required to render JSON responses?
tunesmith超过 11 年前
A problem in general is that all these terms are highly overloaded.<p>Models: For some, models are backend structures that are closely related to database entities. For others, models are data structures that are passed around closer to the front, or structures that controllers pass to views. Some also equate models with domains that have behavior as well as state.<p>Servers&#x2F;services: These are often used interchangeably when they are really not. For instance, your API call has to go to a web accessible server, which might in turn rely on a separate (SOA) service that is not web accessible.<p>Client: This can mean the browser or mobile device (client&#x2F;server), but it can also mean the consumer of a service (client&#x2F;service). This consumer might also be sending serialized data structures or page responses to a browser or mobile device.<p>Controller: This can refer to the logic in a mobile device that is making requests and unpacking json requests. Similarly, it can refer to a part of the javascript in a dynamic frontend that is doing the same. Or, it can also refer to the application that is <i>receiving</i> the network request (and in turn invoking business logic in other layers or making service calls to remote&#x2F;private services) and then responding with json.<p>So, imagine a browser or mobile device that makes a request to a remote &quot;server&quot; and receives a javascript application. The javascript has its own MVC architecture. Ensuing requests to the remote server will receive json responses. The js app might unpack the json in the js app&#x27;s controller, and repack it into different models (data structures) that get passed to the js app&#x27;s views. In turn, the remote &quot;server&quot; could have a controller that receive the initial request and returns a &quot;view&quot; that is the javascript app, but also another controller (more accurately a &quot;resource&quot;) that would receive the RESTful requests and respond with json. These controllers&#x2F;resources could in turn have a bit of business logic to help them make calls - via REST or SOAP - to internal&#x2F;private &quot;services&quot;. These services (on different servers) could have additional business logic to interact with private databases through daos that act on models (which somewhat-but-not-exactly represent the database schema because of ORM).<p>I guess my point is that past a certain point, &quot;fat&quot; versus &quot;thin&quot; doesn&#x27;t really capture the essence of the tradeoffs. It&#x27;s more a series of questions of what is consuming what, what the consumer shouldn&#x27;t have, what the consumer needs, and what the consumer is going to do with it. The big reason &quot;controllers&quot; (?) are getting &quot;thicker&quot; (?) is because there is a push to make the consumer-facing front-end more interactive and dynamic. I think that what the original article is saying is that if you want that, you should do what you can to return your API data structures (whether json or whatever) in as direct a fashion as possible, rather than manually constructing them through a templating technology and a bunch of views that would normally be used to return html.<p>But more generally, I&#x27;d say that unless you&#x27;re talking with a team that knows exactly what you&#x27;re referring to (from previous discussions), it&#x27;s best to just completely define what you mean by client&#x2F;service&#x2F;server&#x2F;controller&#x2F;model&#x2F;etc in each case, because these days, it seems like everyone is using them differently.
nickthemagicman超过 11 年前
BUmp