关于基于API的应用程序开发的困惑

huangapple go评论90阅读模式
英文:

Confusion about API-based application development

问题

传统上,我使用Ruby on Rails构建应用程序,很少提取服务。我现在正在转向更可管理和高性能的东西(SOA w/ API)。

我困惑的是,如果我用类似Go的东西构建API服务器,我到底会失去什么。假设我有一个Article模型,通过系统的过程会是什么样子?我的意思是在ORM、控制器、API等方面。

如果我在Go中有一个API,ORM会在API的级别上,还是我仍然可以使用Rails(它将与API通信)?那么控制器呢?我对这个堆栈是否有意义感到困惑:

  • Go作为API服务器
  • Rails作为应用服务器

我担心的是,如果我采用这种方法,是否会失去Rails提供的许多功能,比如迁移。

英文:

Traditionally, I've built applications using Ruby on Rails, rarely extracting services. I'm now moving into something more manageable and performant (SOA w/ API).

What I'm confused about is what exactly I'm losing if I build an API server in something like Go. Say I have an Article model, what would the journey look like through the system? By that, I mean in terms of ORM, controller, api, etc.

If I have an API in Go, would the ORM be on the level of the API, or could I still use Rails (which would talk to the API)? Then what about controllers? I'm lost on if this stack even makes sense:

  • Go as API server
  • Rails as application server

What I'm concerned about is whether I'm losing a lot of functionality that comes with Rails, like migrations, if I take this approach.

答案1

得分: 1

使用SOA,我不会说这一定是Go或Ruby/Rails特定的。如果你只是使用Ruby或Go本身,情况也是一样的。关键在于你的应用程序是如何架构的。你可以只用Ruby或Go来实现SOA。

服务导向架构有很多好处。

  • 职责明确分离
  • 不同团队可以负责不同的组件
  • 简化应用程序架构的代码
  • 可以降低开发和管理成本
  • 配置灵活性
  • 针对性能监控
  • 简化/逐步软件更新
  • 内在的服务文档(godoc从源代码生成)
  • 针对性单元测试(服务是否正常工作?)
  • 更好的可扩展性

你可能还可以添加更多的好处到这个列表中。

最大的障碍是初始规划,特别是第一次。你要将事情分解到什么程度?哪些事情应该分开?如果你找不到合适的平衡,可能会失去这些好处。

至于如何设计SOA架构,这取决于具体情况。如果我要构建一个包含文章和评论的博客服务,你可以有以下API方法:

提交文章
获取文章
搜索文章
获取评论
提交评论

总体思路是你的服务负责所有工作。前端应用程序只是一个GUI。使用MVC,你的前端仍然可以有一个模型 - 它只是进行API调用而不是数据库调用。

至于使用什么语言,这取决于你。Go是一种很棒的语言。它的社区正在快速发展,但它还很年轻。你可能无法找到在Ruby中本来可以找到的包。你可能最终不得不自己编写。话虽如此,Go有很大的潜力,而且写起来很有趣!

个人经验:我所在的公司过去使用PHP。一年前,我们决定需要做出改变,选择了Go。我们不得不自己编写了一些库,但总体而言,这是一个令人惊喜的一年。我们现在完全使用Go(还有一点C/C++)。

英文:

With SOA, I wouldn't really say this is necessarily Go or Ruby/Rails specific. It would be the same if you were just using Ruby or Go by themselves. What it comes down to is how your application is architected. You could do SOA with just Ruby or Go.

There are a lot of benefits to a Service Oriented Architecture.

  • Clear separation of responsibility
  • Different teams can work on different components
  • Simplifed application archetecture code-wise
  • Can lower development and management costs
  • Configuration flexibility
  • Targeted performance monitoring
  • Simplified/gradual software updates
  • Inherent service documentation (godoc generates from source)
  • Targeted unit testing (does the service work?)
  • Better scalability

You could probably add more benefits to that list.

The biggest obstacle to overcome is the initial planning, especially for the first time. How far do you break things down? What things should be separated? If you don't find the right balance, you can end up losing out on the benefits.

As far as how to design a SOA architecture, that really depends. If I were building a blog service with articles and comments you could have API methods like:

SubmitEntry
GetEntry
SearchEntries
GetComments
SubmitComment

The general idea is your service(s) does/do all the work. The font-end application is just a GUI. With MVC, your front-end could still have a model - it would just make API calls instead of database calls.

As far as what language to use, that really depends on you. Go is an amazing language. Its community is growing fast, but it's young. You may not be able to find a package you would otherwise have in Ruby. You may end up having to write your own. Having said that, Go has a lot of potential, and it is fun to write in!

Personal experience: The company I work for used to use PHP. A year ago we decided we needed to make a change, and we decided on Go. We have had to write a few libraries ourselves, but overall it has been an amazing year. We are now use Go exclusively (with a dash of C/C++).

huangapple
  • 本文由 发表于 2013年8月3日 19:58:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/18032632.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定