简体   繁体   English

软件即服务 (SaaS) 的应用程序设计

[英]Application design for Software as a Service (SaaS)

So I'm currently designing SaaS application.所以我目前正在设计SaaS应用程序。 I'm having small problem with the design.我在设计上遇到了小问题。 Let's say I deploy an application under www.mycompany.com.假设我在 www.mycompany.com 下部署了一个应用程序。 User buys a subscription and therefore gets an access to the application.用户购买订阅,因此可以访问应用程序。 Now what I'd like to have is a 'way' to create a new instance of this application whenever a user buys subscription eg:现在我想要的是一种在用户购买订阅时创建此应用程序新实例的“方式”,例如:

John owns company Vega.约翰拥有维加公司。 When he buys a license for accessing/using my application a new instance is created that would be accessible through www.vega.mycompany.com.当他购买访问/使用我的应用程序的许可证时,会创建一个新实例,该实例可通过 www.vega.mycompany.com 访问。 Once his account is created a new instance of the application is being deployed, new DB created and linked with the newly created instance of my application.创建他的帐户后,将部署应用程序的新实例,创建新数据库并与我的应用程序新创建的实例链接。

The reasons behind that are:这背后的原因是:

  1. John might generate big amount of data, hence having multiple smaller DBs is better than having one for serving each customer. John 可能会生成大量数据,因此拥有多个较小的数据库比为每个客户服务一个更好。
  2. John might store sensitive data which he wouldn't like to store in the same DB as other users. John 可能会存储他不想与其他用户存储在同一个数据库中的敏感数据。

I want to develop the application in Java.我想用 Java 开发应用程序。 The admin application through which I would create new instances of the SaaS application will be also developed in Java.我将通过它创建 SaaS 应用程序的新实例的管理应用程序也将使用 Java 开发。 Now my questions:现在我的问题:

  1. How do I actually achieve that?我如何才能真正做到这一点? Do I simply deploy the same WAR file in application container (say Tomcat) whenever new account is created?每当创建新帐户时,我是否只需在应用程序容器(例如 Tomcat)中部署相同的 WAR 文件?
  2. How do I create the 'vega' subdomain from the administrators application - is that even possible?我如何从管理员应用程序创建“vega”子域 - 这甚至可能吗?
  3. If there's a bug or I want to simply update something and I have 1000 instances of this application how do I do it smoothly?如果存在错误或者我只想更新某些内容并且我有 1000 个此应用程序的实例,我该如何顺利完成?

I'm working on a similar problem/solution right now, although it's written in C#, it will be running in linux with mono and I believe my solution is language agnostic.我现在正在研究一个类似的问题/解决方案,虽然它是用 C# 编写的,但它将在 linux 中运行,并且我相信我的解决方案是语言不可知的。

First of all - to develop a SaaS application like you and me have it - which needs a new instance for every new customer is not really best practice (to the best of my knowledge).首先 - 像你我一样开发 SaaS 应用程序 - 每个新客户都需要一个新实例并不是真正的最佳实践(据我所知)。 Due to the problems you mentioned - setting up a new environment and also handling many concurrent instances, which would include updates or possibly moving them to a different server/infrastructure.由于您提到的问题 - 设置新环境并处理许多并发实例,其中包括更新或可能将它们移动到不同的服务器/基础设施。

For me the decision was due to a bad initial design of the application, simpler data design and in the end better security, as now it's possible to give every customer only permissions to his small subset of the database, and no SQL Injection or other bug on my side can change this - as the permissions are enforced on database level.对我来说,这个决定是由于应用程序的初始设计不佳,数据设计更简单,最终安全性更高,因为现在可以只授予每个客户对其一小部分数据库的权限,而没有 SQL 注入或其他错误在我这边可以改变这一点 - 因为权限是在数据库级别强制执行的。 (you still could have bugs there, I'm fully aware of that) (你仍然可能有错误,我完全意识到这一点)

My Solution:我的解决方案:

Use docker containers .使用docker 容器 It is much more lightweight than a traditional VM, gives you additional abstraction and security in case, for instance, the users are allowed to upload files, … Also deploying a new container is fairly trivial and quick so you can do it within seconds after the user signed up.它比传统的 VM 轻得多,为您提供额外的抽象和安全性,例如,允许用户上传文件……此外,部署新容器相当简单快捷,因此您可以在几秒钟内完成用户注册。

I'm using an Nginx server on the host, as a reverse proxy, which forwards the requests to the corresponding container for each customer.我在主机上使用 Nginx 服务器作为反向代理,它将请求转发到每个客户的相应容器。 The problem here is to restart Nginx after you updated the configuration file, without loosing any traffic, that's a bit tricky.这里的问题是更新配置文件后重新启动Nginx,不丢失任何流量,这有点棘手。

Updating the application is also easy, as you only need to publish a new version of the image, stop all running containers and restart them with the new image.更新应用程序也很容易,因为您只需要发布镜像的新版本,停止所有正在运行的容器并使用新镜像重新启动它们。 However to be able to do this, the containers can't be holding any data, keep that in mind.但是为了能够做到这一点,容器不能保存任何数据,请记住这一点。 - Here the problem is again to update it in a way, the user wouldn't notice, for me - as I've customers only in one timezone it's easy - just schedule it for 4am and fingers crossed nobody is crazy enough to be awake and working at that time :) - 这里的问题再次以某种方式更新它,用户不会注意到,对我来说 - 因为我的客户只在一个时区,所以很容易 - 只需将它安排在凌晨 4 点,手指交叉,没有人会疯狂到醒着并在那时工作:)

This doesn't give you probably 99,999% availability but this isn't something I'm aiming for and it's a great tradeoff for the ease of managing those containers.这可能不会为您提供 99,999% 的可用性,但这不是我的目标,而且对于易于管理这些容器来说,这是一个很好的权衡。 Additional advantages are - you can test the production environment on any linux machine, and you can move the code anywhere you want, just change the Nginx reverse proxy-configuration.其他优点是 - 您可以在任何 Linux 机器上测试生产环境,并且可以将代码移动到您想要的任何位置,只需更改 Nginx 反向代理配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM