How to design micro-services in the below scenario :- - java

I have to design an application using micro services architecture using Java-Spring boot which has the below use cases :-
The user should be able create account in the portal.
User should be able to view / browse the online educational courses and add the courses to shopping cart.
The user should be able to buy the courses by doing an online payment.
The user should be able to view / play the courses which he/she has purchased.
Queries :-
How many micro services should be created and what will be those?
How do we relate the data so that we can map which user has purchased which courses? ( In RDBMS we usually we use a foreign key constraint ) . How is data usually related in such scenarios using micro services architecture?
Which database will be suitable for such architecture and how many data stores will be there?
Request you all to be as specific as possible in the solution.

Answer1:
As per your Requirement you can create following micro services
Registration
Login
Education Courses
Shopping Cart
User Courses
Answer2:
In User Courses table you can store User info as well as course info(both Id's)
Answer 3:
You can use mysql or mongodb or combination of this depends on your requirement.
If you will create 5 schema or will take 5 different database it would be good.

Related

What would be the correct way to model user information in a nosql environment

I have worked with relational dbs for the last 10 years and getting out of the relational model is quite a challenge. I started reading about the query first approach and I get it, now, the attempt to diagram that is what is quite different.
This is what my question is about:
I have users and roles. So, a user can have various roles, or no roles. So, I store roles on a different db.
When modeling with nosql, there are no joins, so, one approach would be to have the user store the roles he manages in the form
UserTable:
{ id:..., name: 'Pedro Zuppelli', roles: [ {id:...,name: 'user'}, {id:..., name: 'admin'}]}
RoleTable:
{id:..., name:'user'}
but, what happens if a role name is updated in the roles table? that would not get modified in the users one.
Also, in the query first approach, if I would like to know which users has which roles I would create a UserByRole table. Now, when a user looses a role, I would not only have to update the user table, but the userByRole one. If a role changes name, the roles table, UserByRole and User table need to be updated.
Should that be done programatically in the service layer, or for instance Spring Data know how to handle it?
Any link to a book that covers this or code sample with complex data mappings would be greatly appretiated, I have been going through a bunch of tutos, videos and so on, and they all manage simple relations.
Thanks!
NoSQL suggest to embed roles and map objects to get list of roles.
{
"type": "User",
"roles": ["admin", "sudo", "wheel"]
}
When you need to change some role names - query all objects and update.
Another option is to use something with integrated query language like N1QL (JOINs, UPDATEs, DELETEs) and imitate relational database with it.

Linking data in java microservices in a database per service implementation

I am building a java / spring microservices where each service has it own database . Let's say i have a user service that stores user information in one of the table and a orders service that stores only the username of the person who orders as described below :-
User Service (UserService Database - User Table )
id firstName lastName username age
1 Chris Brown c.brown 20
2 John Doe j.doe 25
And orders service as below
Order Service (OrderService Database - Order Table )
id username productName productPrice OrderDate
1 c.brown Sony Mic 100$ 20-08-2018
2 j.doe Television j.doe 11-07-2018
Question is what is the best approach to get firstName and lastName from user service while listing the orders . I am aware that microservices should communicate via Rest API , but if i have 1000 users with orders , i will have to loop 1000 times to get the firstName and lastName or take usernames as array , activity which might be expensive .
I have read on using CQRS and event sourcing , but not sure how to best apply it in this scenario .
If you want to build a scalable and resilient application your microservices should not make synchronous calls from one to another (you can read The Art of Scalability book).
This means that when a microservice receive a request from its clients it should have all the data already gathered in its local storage. In your case, you have two possibilities:
add the firstName, lastName columns to the Orders table
create another table with users having id, firstName, lastName columns and make a join when returning data to the clients.
To keep the replicated information eventually consistent with the source (the Users service) you can use one of the following technics:
have a cron job that fetches all the needed user information and replaces all the firstName, lastName columns.
use integration events; in CQRS/Event sourcing architectures you already have the Domain events - you can subscribe to those. If you don't have CQRS but a plain architecture, then you can add triggers to your database that pushes low level mutation events (row created/updated/deleted) to the subscribed services. For more options you can read Migrating to Microservice Databases book by Edson Yanaga
Order Service can keep a shadow copy of limited user information (first name and last name in your case) in its database (using event sourcing) and can build Order object with limited user information all by itself.
Ideally, there should be a REST call to get the data from other MS.
But if these calls are very expensive you should consider changing the DB design and put this required data at a commonplace.

Spring Batch multiple different sources reading pattern

I am trying to found the best design pattern to read multiple different sources, manipulate them and write into a file.
So I have an LDAP server with a branch containing Users and another branch containing Services. An User can have multiples services (represented with multi valued field on User) and I need services details on each User. I also need to log how many Users and Services have been found in the LDAP. First question : any Ldap reader available from spring batch infrastructure ?
I also have a database containing user extras informations in multiples tables (ex: users extras, options, ...). LDAP users can have DB extra informations or not (associated by user id).
I also need to log how many users extras informations have been found in database and log orphan informations (that is not related with a ldap user).
Finally, I need to merge this differents datas into one file with a header (merge LDAP and DB informations).
What is the best pattern to perform that ? (reader/processor/writer pattern seems to be unappropriate to summarize results like Driving query based itemReaders...)

How to design a filter framework for an application?

I'm developing an application that allows to analyze data from different viewpoints. This data is stored in 30+ tables of a SQL database (some tables have a 1:n or n:m relationship).
Now I want to filter this data by different criteria and display the filtered data in my application.
Simplified examples for such filters would be:
Show all products IN category X AND Y which AT LEAST 100 customers from New York have bought
Show all customers that have bought a product with a name starting with 'ab' and a price between 100 and 300 USD
Now I want to provide a filter in my application (similar to ebay where you can filter by category, seller, price, etc.).
My Question:
How do I design such a filter framework?
I don't want to write an SQL Query for each possible combination of filters. Additionally, there are at least 10 subjects I want to query and filter and performance is important.
Is there a best practice on how to build such a filter framework?

Customer Creation from backend with store_id using magento REST api

I was creating a magento customer using REST api. But the customer is being created with some default store_id = 0 .
As a result when I try to login to the magento store I am getting error saying I
Invalid login or password.
In the magento customer creation they haven't mentioned anything about this. How Can I do this? Any kind of heads up will be appreciated.
If I create a customer from front-end page then its getting *store_id=1* and for back-end its *store_id=0*. Both of them have same *website_id=1* So, when trying to login to magento I think we are trying to login different store.
If you set the website ID instead it should take care of this for you.
For your reference
Global: This refers to the entire installation.
Website: Websites are ‘parents’ of stores. A website consists of one or more stores. Websites can be set up to share customer data, or not to share any data
Store (or store view group): Stores are ‘children’ of websites. Products and Categories are managed on the store level. A root category is configured for each store view group, allowing multiple stores under the same website to have totally different catalog structures.
Store View: A store needs one or more store views to be browse-able in the front-end. The catalog structure per store view will always be the same, it simply allows for multiple presentations of the data in the front. 90% of implementations will likely use store views to allow customers to switch between 2 or more languages.

Categories