4

I have been studying microservices and serverless solutions and am playing with an angular frontend hosted on S3 and Lambda functions that talk to various DynamoDb tables via the API gateway on AWS.

Every example and video I read/watch uses a simple CRUD microservices as part of a simple 'todo' application or similar. My problem is where does the business logic sit? If I'm building a complex application I don't want all my business logic in my frontend Angular application. Or do I? I could build an Application API which in turn calls CRUD microservices but that feels like a monolithic approach.

I appreciate there may not be a definitive answer but can anybody advise a novice on best practice?

1 Answer 1

3

There are several best practices I follow in designing Serverless Microservices

  • Start with only few Microservices (Less the better up front, unless you know exactly how the service separation should be, delaying the decision to split)
  • Separate your business logic that goes to the API, and use the handler as a controller in MVC to invoke the business logic. (This will also helps to unit test logic without depending on Lambda).
  • Its not necessary to write only simple CRUD in your API. It depends on your domain and Business Logic required. (But don't build another monolith without separating the code in to different services. Several AWS Service limits will also give you some guide on how much endpoints should be there in a service & etc.)
  • Apply the design patterns available for Microservices (e.g If you want to sync data bases between each Microservice, use Pub-Sub pattern using SNS, DynamoDB Streams and Lambda)
  • Use the Angular App to put most of the presentation logic.
  • Use CloudFront as a proxy and a CDN to avoid CORs.

If you need more information you can refer the following articles I have written on this.

Note: You can use the CloudFormation in Deploying Angular/React Apps in AWS to automate the creation of S3 and CloudFront with best practices.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks for your response, greatly appreciated. Reading your articles as we speak and shall revisit this question shortly.
Read your articles, thank you. Still a bit confused on my question. For example; If I have 2 CRUD microservices, one for "posts" and one for "users" and I need to retrieve posts with associated user details would you create another endpoint that retrieves/combines the data as needed and used by my Angular frontend? Thanks for your time.
If you have two Microservices for post and users, make sure each service is self contained. E.g When querying Posts, it should be having the writers information stored within the service. This is where a document database like AWS DynamoDB fits in for storage. Lets say user update method is there in Users Microservice. Then upon the users data updates, if you have a pubsub messenging system, it should be be possible to sync the data. Also pubsub messenging can be implemented using DynamoDB streams, Lambda and SNS.
Wonderful response, thank you. To clarify; I should store details of the user against their individual post. And if a user updates their username I would synchronise with the post service by updating their username against every post they previously made? Once again, thanks for all your help. It's a very new approach and quite alien to me :-)
Yes. To do this sync use pubsub so that each service is loosely coupled

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.