I'm currently building a "Lifesteam" style website in Rails. A lifestream usually is an aggregate of public content (usually received via APIs).
I'm currently confused about the database structure.
There will be a Users table (as users will be able to sign up and have their own lifestream). I'm wondering whether I should also have a Services table, or have a table for each of the services (Twitter, Delicious etc.) or both. I'm also wondering how these tables would be linked together.
If there was a resource for each service, would it be possible that these somehow inherit from a single Service resource?
Any insight would be a great help, Thanks.
I would probably steer clear of separate tables for each service since it makes it rather difficult to extend the service in the future.
I would be tempted to have a services table which also links to a service_type table. The service type could be RSS or whatever other feed you might support.
Add Feedzirra (http://github.com/pauldix/feedzirra/tree/master) and you're away.
May be use separate table for each service each having a user_id in it. Then they can be automatically linked by the user_id.
I'd use a generic table to handle services in order to make adding a new service easier. You can then handle specificities with extra fields, but in the end services won't be that different from one another.
A generic table to handle services world be great. You can user inheritance to specialize each service.
Related
For example, I have Author service and Book service. Both services have a separate database.
In the Book service, I need to join each book with one author. I think I have 3 ways:
In the Book service, I can communicate with the Author service using some communication channel: TCP, Message Broker, etc.
And I can fetch authors from the Author service, and then make JOIN in the Book service (in the application instead of the database)
In the Book service, I can define a view database, which is a read-only replica of the Author service database (https://microservices.io/patterns/data/cqrs.html). And then, in the Book service, I can make JOIN using the database.
I can join data on the front-end side. On the front-end I can make two HTTP requests to the services, and then join the data on the front-end.
Which way is better?
From your question, it is not quite clear to me where and for what purpose you actually need the joined data from the two sources - for example: does the book service perform an operation for which it needs data from the author service or would it just pass through the joined data to the frontend?
In general, it is fine that each service owns its associated data and another service (in your case: the frontend) retrieves and uses data from several sources. So in my opinion, option 3 is probably a good choice.
Due to the objective of loosely coupled services, I would not recommend creating replicas of one service's data in another service, because you would have to make changes in more than one place in case of a change in your data model. You might also run into problems such as consistency of data.
See also the discussions here, here and here about data sharing between microservices.
(1) I'd avoid, because it introduces an undesirable degree of coupling between your services. Unless your use case dictates that giant listings of book titles are to be accompanied by choice specific data from the author db (for example the author's name), I'd avoid replication, particularly an entire database otherwise once again you're introducing hard coupling. Even though propagation of specific data elements like a name is fine (you're already propagating author id), both the service and it's database should enjoy the freedom to evolve independently and be deployed independently. So (2) is out.
That leaves us with (3), which works very well with GUI based front-ends, where a panel fills in the author details with a rest call, while another panel below asynchronously makes a call to fill in the list of books.
Approach 3 is what you need to take. In order to have it implemented, you need an Experience API (a microservice) which UI will invoke and then that Experience microservice, as the name is self-explanatory will pull data from downstream microservices, massage, scrub and render the UI.
I'm "architecturally against" the idea of having a "Book Service" or an "Author Service." (Of course I know you're using this as an example.)
Here's why: "A Book, like an Author, is a Thing." Whereas, "a Service" is not a Thing.
A "service" should either provide something or do something. And, whatever it does or provides should be complete and self-contained. Books have Authors and Authors write Books and so the two cannot be separated. Don't put the onus on the consumers of your service(s) to have to access several different services to get what they need. If you see that your services have "overlapping concerns," as in this case, then it's a giveaway that your architecture is flawed.
I am relatively new to the UI5 Framework and I have a new use-case in my company that I want to implement with UI5 and OData Services.
Basically the application has two functionalities with different stakeholder:
Role A is able to create new requirements
Role B is able to check the requirements and update them with new
information
How can I implement this the best way? My previous thoughts on that:
Possibility 1:
I have the OData Service in the Backend that is used by two separated application depending on the role. The access is controlled through the launchpad over the PCFG objects. So a specific user can only use the application that he actually needs. I believe that matches the basic granularity of Fiori apps. On the other hand, it invalidates the DRY principle since I would have redundant code like most of the view.
Possibility 2:
I check in the UI5 Framework or OData Service which user is currently using the app and enable/disable the required controls in the controller class. I haven’t come across on how to do this. Is there a way to check which user is logged on? Or how can I implement in the OData service, that only specific information is delivered to the client?
What is the correct way to implement such a use case? Is there a better option that I am not aware of? I would appreciate any thoughts on that matter, thanks :)
Best regards
Suggested Approach
If two roles do not share any common functionalities, then I would go for two separate UI5 apps, so as to keep them simple. In that case, each app would have it's own OData service. But in the backend, you can always have a common class for 'Requirements' which is called by both the OData service implementations. (So as to maximize code reuse). So most of your business logic should be inside the 'Requirement' class, and the OData implementations serve as dispatchers.
To check which user is logged in
This is a common requirement for most of the business applications and it is possible in Gateway/ABAP as well. Within the ABAP context, there is always a system variable available named SY-UNAME, which will provide you the current logged in user's name. You can use it further to derive the user's role.
I'm new to Grails and web development. I started doing a project on Schedule management website stuff. I came across the Service concept that is provided by Grails. I understood the concept, but still I have confusion on when to use services.
For example, I need to implement a search module, where the manager can search for a user to find his schedules. In this case it will be good to implement it as a controller or as a service?
So,
When and where should I use Service?
To add to Grooveek's answer;
It is also nice to use Services to keep your Controllers nice and clean.
So Views just render data to the screen, Domain objects store state, Controllers route the user around the application, and Services perform the work.
I don't have enough reputation to comment on an answer or vote up so I have to provide an answer that really should be a comment. Anyways...
+1 on #tim_yates answer. Gotta love thin controllers. 2 things that I would add to the description of a controller:
Would be to translate parameters from the browser before hitting a service (e.g. Date, number, etc.)
Would be to translate data returned from services into something consumable for the views.
For me, ideally, services would never deal with translating a String parameter to it's inherent type. Or deal with building a model to be displayed on a view.
What and where I should use Service?
When you want your controller do to something that may be reused by other controllers
In our application we're doing a functional separation of service. We have a CorePersistanceService, which provides method to create, delete, update and manipulate Core Domain Classes (core for us).
I think persistance services are a good way to reuse GORM code throughout Grails code. You can create method in domain classes, but I don't like that, it's way less maintanable I think
We have a PDFService class for our PDF creation, a SolrService which connect to Solr, a Statisticservice that gather all our methods which collects statictics on our datas
Services in Grails are a manner to gather methods around a particular functional theme, in order to give possibility to reuse them in controllers (I forgot to mention our SecurityService, which is a pretty good Cross-Applications Example)
I’m working on a Grail’s project that has some Domain objects not persisted on the database. They are managed thru a REST API, so all their CRUD operations will be done with this API instead of the database.
The point is to still be able to use some interesting Grails plug-ins (like searching using Compass).
For instance, the administration the Domain objects Users is going to be managed with the REST API, so when the Users list is displayed a the REST method to retrieve the list of users will be invoked on the remote server. I hope this use case is clear enough :)
I can think on several ways to design that but I'm not sure what’s the best:
Should I create the Domain Objects in the controller (and delete the
previous Users stored in memory)?
It seems it’s possible to define a Domain Class not persistable (with
mapping I think) but I’m not sure if this is the best approach or
where to load the data.
It is better not to model as a Grails the User as Domain object?
Thanks in advance!
I would wrap the REST interactions in a service, and call the service from a controller. In that case, the service would get the response and create its objects, passing the list back to the controller. Controllers should just handle incoming requests, invoke application components, and return responses.
It seems you want models to represent the data in the other application, which is a good idea. Since you don't need GORM, you might want to define them in the 'groovy' folder of your app instead of the domain models folder. Then I think they will just be objects.
I'd go with non-domain objects in src folder - though, need to check if it's possible to use the mentioned plugins with them.
I wonder what domain class functionality you wish to get out of non-persistent classes?
Problem: Our web console shows a list of all computers on which our application is installed. Each machine has some identification information that can be associated with it. Simple strings like department name, team name etc. We need to make it such that the user can change the name of these identification fields and add/remove as many as he wants. How can we best implement this?
Initially i thought that i could implement this as a singleton. In the application start, i could read the last set identity field names from the db and create a singleton instance of a list of strings. This could be passed around to all functions that need to display or access the identity information. The appeal in this option is that if the user changes the identity fields name from the ui or adds or removes the fields, i can simple modify the singleton object and the change will be reflected.
However i feel there must be a better way to achieve what i want. Because there a lot of such information that the user can modify at will and we need to track them.
Any suggestions?
Just use the objects from your ORM to maintain and use this information in the application. Many ORMs have the ability to cache this sort of thing, so it's not like you will lose any speed over it.
I'm not a big fan of using a Singleton to do this. It's hard to unit test, and you'll still have to persist it to the database eventually.