How to sync data between two independent backends? - javascript

I want to sync data between two different backends, one written in Javascript and the other in Java.
The JS backend has its data stored in a MongoDB but the Java backend contains some hardcoded data that I need to fetch in order to store it the DB of the JS backend.
Now my question is what are the possible solutions to do that from an architecture perspective?

You have a "Split-Brain". You can only use one Data Store. You have to migrate the Hardcoded Date to MangoDB an to read the data from there.

Related

How to access excel data in front-end application

I have an excel with some constant values(these values would be updated quarterly), I need these values to make calculations and display in my front-end application. Currently there are 2 approaches to this problem that have been implemented:
to use any third party library and convert required excel data to json and store it in front-end application and then use it.
to create a data service that would read excel data and return whenever its called
Both these approaches work well but I am looking for is something more innovative and maintainable.
Thanks in advance for your help!

How to do full-text search in a MySQL table using Fuse.js and Redis?

I have a table with a thousand records in it and I want to do a google like search full-text/fuzzy search.
I read about MySQL v8's Full-Text search and let's say we don't have that functionality yet.
There is this JavaScript library called Fuse.js that do fuzzy-search which is what I need.
I can combine it by creating a API that returns the table data in JSON format and then pass it to Fuse.js to do a fuzzy-search.
Now, I think it's not recommended to load all data from table every time someone wants to search.
I read about Redis, and the first thing that came in my mind is to save all table data in Redis using JSON.stringify and just call it every time instead of querying the database. Then whenever a data is added in the table, I will also update the contents of the data in Redis.
Is there a better way to do this?
That is a very common caching pattern.
If you need a more efficient way to store and retrieve your JSON to/from Redis you might want to consider one of the available Redis Modules.
e.g.
RedisJSON allows you to efficiently store, retrieve, project (jsonpath) and update in place.
RediSearch allows you to have full text search over Redis Hash and efficiently retrieve data according to the user's query.
Last
RedisJSON2 (aka RedisDoc) combines both modules above, meaning efficient JSON store and retrieve with Full Text support

Best practice for database data rearrangement/transformation?

I have a MySQL database and retrieve data using php on a website where I would like to visualize the data in different ways. For this I also need to transform the data (e.g. creating sums, filtering etc.).
My question is now at which step of the data flow this kind of transformation makes most sense, especially regarding performance and flexibility. I am not a very experienced programmer, but I think these are the options I have:
1.) Prepare views in the database which are already providing the desired transformed data.
2.) Use a PHP script that SELECT's the data in the transformed way.
3.) Just have a SELECT * FROM table statement in PHP and load everything in a json, read it in js and transform the data to a desired version.
What is best practice to transform the data?
It all depends in the architectural design of your application.
At this time SOA (Service Oriented Architecture) is a very used approach. If you use It, logic use to be in the services. Database is used as a data repository, and UI manage final data in light weight format, only really needed information.
So in this case, e.g. your option number 2 is most appropriated.

Ajax data management

I'm not really comfortable working with Ajax as I just started using it.
My question is as follows:
What is the best way to manage data fetched using Ajax?
I have a script that fetches data from a database and displays it in different ways depending on the users filters and order criterias. So far, I query the database for every requests and was thinking if it could be better to fetch all data at once, store it in an array of objects and run queries like ordering and category filtering locally using Javascript.
Any gains in termms of speed and/or performance?
Thank you.
Show an example first. An example of the data that is fetched from database and the required way to arrange them. You can use XML or JSON or straight JavaScript object. the question is which one do you like to work with? I would choose the returned data from database to be in XML format. Show us an example of code where you don't know what to do.

ORM for Javascript/JSON

I am working on a web application that gets JSON data from the server (Ruby/Rails) into the client using jQuery/ajax and then renders it to the browser using jQuery to populate the DOM. To simplify access to my data on the client side, I would like to use an object-relational mapper similar to ActiveRecord, but which starts with JSON data instead of data directly from a SQL data source.
Are there any such ORMs in Javascript that convert a JSON data set (itself derived from a set of SQL queries on the server side) to a set of ActiveRecord-like objects?
I may be missing something here, but JSON (JavaScript Object Notation) is already a Javascript object in and of itself.
If the data you are getting from the server doesn't map well to a usable Javascript object, I would argue that it's the server side that needs to change to return a more useful serialized object rather than a simple recordset.
ExtJS has a very nice JsonStore class
There is CouchDB which is a DB written in Erlang that uses HTTP as the transport. This eliminates the need for middle-ware and permits you to navigate the DB directly with AJAX calls. I can't speak good or bad about it. I haven't heard much about it in months and it seems as if the hype train departed a few years ago.
You can't have an ORM to a remote DB in Javascript.. An, ORM requires transcendental knowledge of the DB schema, and sending that out with an API just isn't that pragmatic as of yet.
For persistent local storage, there is the now deprecated Google Gears and the HTML5 Clientside DB.
Yes there is JSON ODM. Exactly what you are looking for. If you need a method that is not supported yet post an issue and I'll try my best to support it as soon as possible.
If you like it please give it a star!

Categories