Deciding which microservice should write to the database

Let’s assume the following architecture where

  1. EventCreatorApp creates an Event which is logged to DB and sent to WorkerApp for processing
  2. WorkerApp processes the event, handles failures, etc.
EventCreatorApp --> [ DB ]         |          ---------> WorkerApp 

Once WorkerApp is done, I want to update the event row in the DB with the outcome of running that event.

My question: Which app should write the outcome to the database?

If WorkerApp writes the outcome to the db the logic is nicely decoupled (one app creates events, one app executes events) but I have two apps writing to the db. What’s worst, I want to deploy WorkerApp on an AWS Lambda, and that would mean opening a new connection to the db for each event processed.

If EventCreatorApp writes the outcome to the db I don’t have any db access problems, but it feels like I’m pushing into EventCreatorApp some logic that doesn’t really belong there, and in general I’m coupling the two apps a bit since EventCreatorApp would have to wait for a response.

Which solution is best?

What are the best practices of designing database to serve multiple apps within one ecosystem?

To clarify the question here is the scenario. There is a web app which implements RESTfull API with JWT authorization. It runs on PHP/mySQL at the back and Angular2 in front.

Then comes another app which would need to use the same user credentials as the first one but it has its own context. The two apps will integrate with each other over time more and more, however the extent to which they will integrate with each other is still unclear, except for authorization and subscription payments. Think Atlassian ecosystem as a broad example of integration and account administration.

How would you design the database and APIs around it in such a case?

Synchronization data between API (server) and local database : C#

I hit an API which gives a list of chairs with their location. I save this data in my local database. Whenever I received updated data like add a new chair, update location of the chairs and delete a chair from the API, I must sync server data with my local database. I also assigned these chairs with different sections in the local database.

Chair server class:

  1. ChairServerId
  2. Description (unique key)
  3. Location

Local DB class:

  1. ChairLocalDBId
  2. Description (Unique)
  3. location

I have a Section Table in local database. It has two columns i.e. SectionID and SectionName.

Also, there is a relational table between chairs and sections. It has two columns.

I have a SectionChair Table in database has also two columns i.e. SectionID and ChairLocalDbId.

Below are different test cases:

  1. Sync with same location of chairs =>

    One :If multiple chairs are coming with same location, it shouldn’t add into local database. It should show a message to the user – show duplicate chairs with location to the user.

    Two: First time, I did a sync and a chair (chairOne) is added with location ‘locOne’ in the local database. Now, I will add one or more chairs (chairTwo) with same location ‘locOne’. So, when I do Sync, it will not add chairTwo in localdatabase and also not delete chairOne from the local database. It just shows a message to the user – show duplicate machines with location to the user.

  2. Delete a chair from the Server (API) =>

    If a chair is deleted from the server, it should be deleted from the local database. Validation: if a chair is assigned to any sections, it shouldn’t be deleted. It should give an exception –“ please first unassigned this chair from the Section and sync again.

  3. Add a new chair from the Server (API) =>

    If a chair is added in the server, it should be added into local database.

  4. Swapping Locations =>

    One: 3. If we swap a two or more chairs in the API, location should be also swap in the local database. Example: Chair 234 on locOne location and Chair 345 on locTwo location in both the API and local database. After that, user swap the machines in the API like Chair 234 on locTwo location and Chair 345 on locOne location. When I do sync, the same swap should be happen in the local database and update the new location for the chair in the local database.

    Two:4. Major issue: if we do swap like first point, Section should also be updated into SectionChair table. Example : Chair 234 is located in 562 and is assigned to Section 5 place X. It is switched with chair 789 located in 223 which is in Sections 8 Place Y. When synced, chair 234 should change to Section 8 Place Y and chair 789 should change to Section 5 Place X.

Please suggest me a good approach.

How to write a database class in python? [on hold]

I’m a database beginner and I want to know how to turn my “database code” into a real python class. Because I have a little bit of experience in OOP I’m actually not feeling very well calling that my database and sadly I do not now how to approach this problem. Literature on that topic would be appreciated to get my mind around databases and database design.

import pymysql as PyMySQLdb  conn = PyMySQLdb.connect('localhost', 'schema', 'superdupersecretpassword', 'fvt') db = conn.cursor(PyMySQLdb.cursors.Cursor) 

How to handle continuous update of ON/OFF button in the database

This might be a stupid question but I don’t how it goes.

My questions can be based around the Facebook like button. That button can me spammed how much we want, liking or disliking. And my question is how are they handling such a continuous update action and not putting workloads on the server. Does this update the database everytime? Is there a queue implementation for it, if so how does it theoretically work?

These are my only two solutions to this “problem”.

Cognito Forms: Need to store data into own database rather than to store data on Cognito forms database

I am implementing a web application where I want to provide the user the facility to create their own forms and data can be stored into our database. I would like to use Cognito forms and give that platform in my application by using Iframes. But have some questions that I am not able to figure out after spending enough time on google. Questions are:

  • The client does not want any 3rd party application where the data can be shared. I know the data is encrypted and secure and stored on Azure (No SQL). But still; is there any option in Cognito forms where data can be directly saved into our database without storing into cloud?

  • We don’t have any fixed forms that we need to create, our main purpose of using Cognito is to provide the feature to end user, where he/she can create his own forms through our application and data (along with form structure), can be stored into our database only. Right now, I didn’t find any option or trigger where, whenever a user creates a new form, it can trigger some action, and through that trigger/action that new form structure can be stored into our database. Can anyone help on this?

Persisting user-deleted items in a database

I’m building a web application, in which users have their own set of Topics. Since Topics are recorded for reporting purposes, it’s important that Topics used previously are not deleted, so that they can be referenced by future reports.

In my relational database, Topics are associated to users through a user_id. My idea is to, rather than users deleting a Topic, have it be orphaned by setting its user_id to null. This way, the Topic can be referenced by id in reports, but from the user’s perspective, it is deleted.

Is this good practice? Should I instead move the Topics to a deleted_topics table?

storing statistical data in the database [on hold]

I have multiple similar threads (primitive bots) in the application. Bots perform some actions until the reach the goal. I want to record each step of the thread in the database in order to analyze it later.

Each bot has its unique identifier and I will provide them with the timestamps too. So the record looks like this

record     bot_id     area_id     x_position     y_position     group_id     timestamp 

However I don’t want to block the thread while it trying to store the data in the database. So I decided to send messages to some message broker and then use some separate process that will read those messages and store them in the database.

However I can’t decide what technology to use. As far as I can understand I can use any for my case – I can use any broker, can use any database (from relational to not). I do really like to experiment with different tools.

So what could you recommend that would be effective for my case?