Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Surman's avatar

Sync between Laravel app and an android app

I'm currently synchronizing an android app that internally uses a SQLite database with my Laravel web (using MySQL), with each POST from the android app I receive a timestamp ($request_timestamp) and JSON with records data to update/insert my Laravel Appp at the same time I return a JSON with the collections that needs to synchronize to the android app side, filtered by a timestamp (created_at|||updated_at|||deleted_at>$request_timestamp) that I receive in the request.

Live sync is not an option, its an app that is usually used offline to collect data and only sync it when wifi is available.

Is this the best way? I'm worried about running out of memory in case of returning a json that is too large.

Would it be more efficient to exchange a raw SQL?

Any advice is welcome.

0 likes
2 replies
AddWebContribution's avatar

Synchronizing a SQLite database with a MySQL database using JSON is a common practice and can be an efficient way to transfer data between the two systems. However, the size of the JSON data returned in each request is a concern, as you mentioned.

A large JSON response can cause memory issues and slow down the synchronization process. In this case, it might be more efficient to exchange raw SQL statements between the two systems.

With raw SQL, you can write SQL statements to insert, update, or delete data in the MySQL database, and the statements will be executed directly on the database. This can be faster and more memory-efficient than exchanging data in the form of JSON.

However, raw SQL has some security risks, such as SQL injection attacks. You will need to make sure to properly validate and sanitize the SQL statements before executing them on the database.

In conclusion, it depends on the size of the data and the specific requirements of your use case. You can consider using raw SQL if you need a more efficient and memory-friendly solution. However, be sure to consider the security risks involved and take the necessary precautions to protect your database.

1 like
Surman's avatar

Thank you @saurabhd, it's precisely the memory issues when handling large JSON collections that I was worried about.

Please or to participate in this conversation.