Hi Guys,
I have a decision to make to solve a problem, I’m describing the problem below.
Application Overview
I have an ASP.NET MVC 4 webApp which uses Rest Api for almost all the tasks, from Login to CRUD on the records.
The rest api is being developed by a separate disjoint team and the webApp is being developed my me.
There is a particular scenario which leads me to think that something is not right may be the Api is having an issue or I’m not developing the WebApp the right way.
I made a screen for Employee creation, it collects several information related to an employee, on submit to the server I collect these information serialize them into json and send them to Resource URI using the POST method.
The problem is in order to create a single employee I would need to hit four Resource URI one by one,the Person needs to be created first (its the independent record) and then I can proceed with the person_id to create Phone,Email and Address.
Person > (Phone | Email | Address)
Possible Issues:
Now If the Person creation fails I would show user that the operation failed and he/she could try again.
If the person creation succeeds but one or more preceding record creation fails then actually Employee creation fails,it’s kind of a transaction all record should be created to successfully create employee.
Also a useless person will be hanging around of no worth and then the Application user might try to create the employee again and this problem may happen again.
Possible Solutions
A) Solution at my End:
Make a windows service running with a scheduler,which checks a DB if failed requests are there,and if it finds any it performs the api request to complete the tasks.
B) API Level Solution:
Make an Employee Resource URI which is able to receive the json of all the distinct json objects in a single go and respond with result.
Of course these separate json object may correspond to separate DB tables and the API developer will handle them through transaction.
C) Use QueueBackgroundWorkItem
use the QBWI to quickly make several async request for the failed resources and return with failed and success message also log and email the admin,no need to manage a separate Windows Service and a DB.
for more details on QBWI.
Remarks:
I will go for the solution B ,its seems like the best option but due to time constraint I might need to apply the solution (C)
Guys I need you to critically examine the scenario and the solution sections and provide me analysis and the best possible solution.
B definitely sounds like the only sane choice.
A means depending on implementation details of the REST API. It makes the “transaction” very fragile, breaks encapsulation, and other bad things.
C I’m not entirely sure what you’re saying you’ll do with a QBWI (beyond the email to admin part), but it doesn’t sound like an actual solution to the problem. Something as simple and fundamental as transaction semantics definitely needs to be handled by the software, not by human admins.
In the real world, the “disjoint team” may fail to deliver a real solution. This would be when you talk to business managers and explain to them that you can do a hacky workaround (A or C) in the short term but you really need the other team to give you a proper API someday. They’re the ones in a position to decide whether it’s better for the company to do the workaround now or have you do something else for the time being.
2
there is problem in ur requirement gathering
1st u said “…(its the independent record) and then I can proceed with the person_id to create Phone,Email and Address“
then u said : If the person creation succeeds but one or more preceding record creation fails then actually Employee creation fails“
means it is not independent.
lets assume its independent
then it means user can add orr update its address resource, phone resource etc after words.
solution like u can redesign this screen in way that first u create user with Person Resource and then get his other informations afterwards.
and if its dependent then u cannot disjoint the resource like that, in API u have give complete information to perform task.
User creation is a task and its complete information is all together.
4