Firebase / Web Component - issues with same time data submits and deletes?

Hi @TIMAI2, as I previously wrote in this post, in my app I use Realtime Database with your web component strategy.

When more users try “at the same time” to write/delete values in realtime database, I receive: runtime error (no message) - close the app.

The message is probably due to the need of Concurrency control. How can I prevent data conflicts?

Is there a way to implement Concurrency control in Mit App Inventor with your web component approach?

The issue you suggest is most likely caused by how your app is handling responses from Firebase. I would suggest you have a look at how you are handling these, both the response codes and the response content (note that a Delete request does not return any response content)

If you truly believe you are getting conflicts from CRUD operations on your data, then you could consider using E-Tags in your Firebase requests.

From Firebase documentation:

For high-concurrency scenarios on the Blaze plan, Firebase supports up to 200,000 simultaneous connections per database. If you exceed these limits on the free Spark plan (100 connections), subsequent connections are rejected until existing ones close.

You might want to read and digest this:

FWIW, in general, and if a user has permissions to read and write:

CREATE & UPDATE (write) will do the same thing, a value will be created if it does not exist, or updated if it does.
READ will return the values found at the time of the request
DELETE will delete the requested value, or do nothing if that value does not exist.

Hi @TIMAI2 thank you!

In order to allow you to better understand the logic of my app, I “try” to summarize…

In my Realtime Database I have

-event_1
time_1 : value_1

-event_2
time_2 : value_2

-list
event_1
event_2

where list is a list. Any user can create and delete events.


1 - BLOCKS TO CREATE EVENT

set tag1=true
when BT_save click
set WEB.url to … list
call WEB.get

when WEB.GotText (if tag1=true)
add items to list
list: list
item: event_3
set WEB.url to … list
call WEB.PutText list
set WEB.url to … event_3
call WEB.PutText time_3 : value_3

PROBLEM ENCOUNTERED
When the app is used by only one user, there is no problem.
When two or more users create an event "at the same time," I do NOT receive error messages, but I lose items in the list.
For example, if two users wanted to create event_3 and event_4 "at the same time," the final result would be

-event_1
time_1 : value_1

-event_2
time_2 : value_2

-event_3
time_3 : value_3

-event_4
time_4 : value_4

-list
event_1
event_2
event_3 (or event_4)


2 - BLOCKS TO DELETE EVENT

set tag2=true
when BT_cancel click
set WEB.url to … list
call WEB.get

when WEB.GotText (if tag2=true)
set global "list" to responseContent
for each item in list
set WEB.url to … item
call WEB.get

when WEB.GotText
set global "values" to responseContent
if (condition)
remove list item
list: "list"
index: (index)
set WEB.url to … item
call WEB.delete
set WEB.url to … list
call WEB.putText list

PROBLEM ENCOUNTERED
When the app is used by only one user, there is no problem.
When two or more users simultaneously try to delete one or more events, I receive the message:
”Runtime error - no error message”


How can I solve this?

Thank you TIMAI2!!!

As previously said, the issues lie in how you are handling the data in your app, not with firebase. The chances of submitting data at exactly the same time to firebase (time measured to the millisecond), are extremely remote. If such an event should occur, one of the submissions may fail, as opposed to overwriting the one that got there first. Your response code/content should indicate this failure.

To be able to work towards a solution, I would need to see the structure of your firebase data.

It would also help to actually see your relevant blocks.

(If you feel unable to do this, prepare an example aia project and related firebase data that replicates the issue, and share that instead)

If you really want help, you need to start providing these things when you have a question or problem.

You may also find this useful (about E-Tags which i also mentioned) :

Thank you @TIMAI2 , I will work on this…and hope to solve :slight_smile: