2023-03-27

Rails: Two Applications using the same database (WebService <--> API)

Here on Stack has the same question that I wanted to do but my question has one different aspect.

Today I have a rails application that's managing the web application and API but wanna separate it to manage the server resources more efficiently.

The question is: How App1 could know when App2 inserts a new record? Rpush? Sql Trigger? Or transform Api into a gem?

App1 - WebService Port 80 using DB1

class Post < ActiveRecord::Base
 belongs_to :user
 before_save :do_stuff_when_app2_insert_record #I know this doesn't work in this environment  

 def do_stuff_when_app2_insert_record
  ...
 end
end


App2 - API connection - Port 8080 using DB1

class Post < ActiveRecord::Base
 belongs_to :user
end

Post.create(name: 'post')


No comments:

Post a Comment