简体   繁体   English

微服务应遵循的选项:Spring Boot或AWS Lamba

[英]Which option to follow for microservices: Spring Boot or AWS Lamba

I come from Java / Java EE background and new to Microservices and AWS; 我来自Java / Java EE背景,是Microservices和AWS的新手。 though, I did lot of reading over it. 不过,我做了很多阅读。 I tried my first microservice with Spring boot and I am impressed with Spring Boot. 我用Spring Boot尝试了我的第一个微服务,Spring Boot给我留下了深刻的印象。 I also used AWS for past 2 months and I am bit familiar with it now. 我在过去2个月中也使用过AWS,现在对它有点熟悉。

Now I am working on a big application and thinking of designing the complete back end (APIs) and would like to use micro services for it - though I would still use only few microservices: One for managing users, and three more with business logic. 现在,我正在开发一个大型应用程序,并考虑设计完整的后端(API),并希望为其使用微服务-尽管我仍然只使用很少的微服务:一个用于管理用户,另外三个用于业务逻辑。 I will have to also handle authentication. 我还必须处理身份验证。

Based on my research and work I am considering two options: 根据我的研究和工作,我正在考虑两种选择:

Option 1: AWS Cognito (for social media login support) + AWS API Gateway + multiple AWS Lambdas (Java Code) + One DynamoDB (preferably otherwise RDS MySQL). 选项1:AWS Cognito(用于社交媒体登录支持)+ AWS API Gateway +多个AWS Lambda(Java代码)+一个DynamoDB(最好是RDS MySQL)。 My concern is Can I write complex business logic and handle complex tables relations (such as Many-to-Many; eager/lazy fetch, and so on) in AWS lambdas, which are very neatly done in Spring Boot + Spring Data JPA 我的关注点是我可以在AWS lambda中编写复杂的业务逻辑并处理复杂的表关系(例如,多对多;急切/延迟获取等),这些问题在Spring Boot + Spring Data JPA中非常巧妙地完成了。

Option 2: Start with writing business logic in Spring boot, that is, four spring boot applications with either MySQL or DynamoDb as backend; 选项2:从在Spring Boot中编写业务逻辑开始,即以MySQL或DynamoDb作为后端的四个Spring Boot应用程序; and deploy them on AWS EC2; 并将它们部署在AWS EC2上; I can also implement one more Sprint boot application with JWT for authentication My concern here is How to manage authentication (one entry point for all API's) for multiple spring boot applications; 我还可以使用JWT来实现另一个Sprint引导应用程序以进行身份​​验证。我的关注点是如何为多个spring boot应用程序管理身份验证(所有API的一个入口点)。 If i will face challenge in integrating with AWS API Gateway (for centralized management of Authentication & Authorization); 如果我在与AWS API Gateway集成(用于身份验证和授权的集中管理)方面面临挑战; and Will I face challenge in integrating with AWS Cognito if I want social media login 如果我想要社交媒体登录,在与AWS Cognito集成时是否会面临挑战?

I don't want face lot of complications in later stage, therefore, I need help in deciding. 我不想在以后面临很多麻烦,因此,在确定方面我需要帮助。

Many Thanks 非常感谢

When you are having complex business logic/complex relationships which can take more time to execute then you need to be cautious while using combination of Lambda and API Gateway for following reasons: 当您具有复杂的业务逻辑/复杂关系时(可能需要花费更多时间来执行),因此在结合使用LambdaAPI Gateway时需要谨慎,原因如下:

  1. Api Gateway is very useful in case of writing API only if you are sure that your APIs are fast and will bring the response in quick time. 仅当您确定自己的API速度很快并且可以带来快速响应时, Api Gateway在编写API的情况下才非常有用。 Currently, API gateway has the hard limit of timeout after 29 seconds . 目前, API gateway29秒后的超时严格的限制 This means if your API takes more than 29 seconds then it will straight forwardly terminate that request. 这意味着,如果您的API花费的时间超过29秒,那么它将立即终止该请求。
  2. Something similar goes with lambda as well. lambda也有类似的情况。 Lambdas are specially designed to handle smaller chunks of processing. Lambdas专门设计用于处理较小的处理块。 Currently it supports maximum memory of 3008 MB and timeout of 5 minutes . 当前,它支持3008 MB的最大内存和5分钟的超时 After 5 minutes lambda will terminate the processing of the request. 5分钟后,lambda将终止请求的处理。

So, your Option 1 has these limitations otherwise it's really easy and time+cost effective to use that combo along with AWS Cognito . 因此,您的选件1具有这些限制,否则,将该组合与AWS Cognito一起使用确实非常容易,并且节省了时间和成本。

Now let's see about your Option 2. 现在,让我们看看您的选择2。

Option 2 is widely used generally for monolithic applications as they are big, more complex and time consuming. 选项2体积大,更复杂且耗时,通常被广泛用于单片应用。

If you are thinking to go with it then I would like to let you know that API Gateway won't be useful because of the timeout hard limit mentioned above. 如果您打算使用它,那么我想告诉您,由于上述超时超时限制, API Gateway不会有用。 In that case, Authentication can be done using widely available techniques like JWT , OAuth , Basic Auth or even AWS Cognito . 在这种情况下,可以使用广泛使用的技术(例如JWTOAuthBasic Auth甚至AWS Cognito来完成身份验证。

So, in my opinion if you have microservice based architecture then there shouldn't be any issues going with Option 1 provided time performance is honored! 因此,我认为,如果您具有基于微服务的体系结构,那么只要尊重时间性能,那么选项1就不会有任何问题!

Happy coding! 编码愉快!

After investigation I chose AWS lambdas. 经过调查后,我选择了AWS lambda。 My application is a event management application and I want event driven architecture. 我的应用程序是事件管理应用程序,我想要事件驱动的体系结构。 In general question should have been container vs lambdas and I found a good comparison . 总的来说,应该是container vs lambdas,我发现了一个很好的比较 Starting with Spring is easy because it is so familiar to one with Java background. 从Spring开始很容易,因为它对Java背景非常熟悉。 It is good to write micro services with business logic and exposing as HTTP REST APIs. 最好编写具有业务逻辑并以HTTP REST API形式公开的微服务。 I was reading domain driven design and it is good to decide micro services size based on boundaries (bounded contexts). 我正在阅读域驱动的设计,因此最好根据边界(有界上下文)来决定微服务的大小。

But I also see going with Spring boot I will have to manage authentication (for an event management application we need social media login support), authorization, users, roles, policies, and also finally integrate microservices with API Gateway. 但是我也看到使用Spring Boot,我将不得不管理身份验证(对于事件管理应用程序,我们需要社交媒体登录支持),授权,用户,角色,策略,并最终将微服务与API Gateway集成在一起。 AWS Serverless authentication and authorization is very sophisticated . AWS无服务器身份验证和授权非常复杂 Using NoSQL Database such as DynamoDB follows some of the microservices guidelines such as CQRS. 使用NoSQL数据库(例如DynamoDB)遵循一些微服务准则,例如CQRS。 With Lambdas, the boundaries will be too small but in my use case AWS Lambdas suits better. 使用Lambdas时,边界将太小,但在我的用例中,AWS Lambdas更适合。

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

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